Cannot click on EditText after adding it to WindowManager

后端 未结 1 1145
名媛妹妹
名媛妹妹 2021-01-19 15:43

I am creating a layout pretty much dynamically. What I am doing is, creating an EditText, adding it to a RelativeLayout object and putting it to UI through WindowManager. Ho

相关标签:
1条回答
  • 2021-01-19 16:15

    here's how you put a view on top of everything:

    final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
    param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    final View view=...
    final ViewGroup parent=(ViewGroup)view.getParent();
    if(parent!=null)
      parent.removeView(view);
    param.format=PixelFormat.RGBA_8888;
    param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    param.gravity=Gravity.TOP|Gravity.LEFT;
    param.width=view.getLayoutParams().width;
    param.height=view.getLayoutParams().height;
    final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    wmgr.addView(view,param);
    // TODO handle overlapping title bar and/or action bar
    // TODO you must add logic to remove the view
    // TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW
    

    you can put the view inside XML if you wish to easily see how it should look like. the code i've written will detach it from your layout and put it on the window itself.

    0 讨论(0)
提交回复
热议问题