Starting a View from a Service?

后端 未结 6 1468
攒了一身酷
攒了一身酷 2020-12-10 17:52

Already asked a similar question, yet without much luck.

Suppose I have a service and I need a view to pop up above it. In the same time, they both should be intract

6条回答
  •  执笔经年
    2020-12-10 18:19

    Yes it's possible, what you need to do is call the WindowManager service and add your view via the same.

    WindowManager windowManager=(WindowManager)getSystemService(WINDOW_SERVICE);
    LayoutInflater inflater=(LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
    RelativeLayout layout=(RelativeLayout) inflater.inflate(R.layout.box,null);
    

    You need a WindowManager.LayoutParams object which should contain the parameters for the layout

    windowManager.addView(layout,params);
    

    Well, adds the view

提交回复
热议问题