Possible to inflate an XML layout in a Service? (Android)

前端 未结 1 1079
孤城傲影
孤城傲影 2020-12-25 14:33

I want to inflate an xml layout in a service. How do you do this? I tried to use inflater and Window Manager but I think it don\'t work. Any tactics on this? Thanks.

<
相关标签:
1条回答
  • 2020-12-25 15:23

    it is possible to place a graphic on the service the code is this:

    li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    //WindowManager.LayoutParams.TYPE_INPUT_METHOD |
                    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,// | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                    PixelFormat.TRANSLUCENT);
    
            params.gravity = Gravity.RIGHT | Gravity.TOP;
            myview = li.inflate(R.layout.traslucent, null);     
    
            wm.addView(myview, params);
    
    0 讨论(0)
提交回复
热议问题