Why my EditText copy/paste menu is under the EditText? How change the z-order of popup window?

半腔热情 提交于 2019-12-03 17:07:11

问题


NOTE

If someone know how to order (z-order) Windows added via windowmanager, i will also accept the answer because it's will answer all the question. Actually i only find to do windowManager.removeView(MyView) following immediatly by windowManager.addView(MyView) to put a view in front of the other, but this is not ideal because it's visually remove and add the view. it's look crazy that their is no build in function in android to do such a simple think.


I create a view (linearlayout) that contain an EditText. I add this view in the activity via WindowManager.addView (view, Layout_Params);

but i have problem that every popup the edittext will generate (like copy/past menu or word suggestion menu) will be under other views, under even their owning EditText view (not on the picture the edittext have a transparent background)

ill be

i create the views (ie: LinearLayout) with theses layout params :

protected WindowManager.LayoutParams createLayoutParams() {
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.LEFT | Gravity.TOP;     
    p.width = 0;
    p.height = 0;                       
    p.format = PixelFormat.TRANSLUCENT;
    p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED;
    p.flags = NOT_FOCUSABLE_FLAGS;
    // TYPE_APPLICATION allows for popups in browser windows (like edit menus)
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION; 
    p.token = null; 

    return p;
}

and i show the view (who contain just an edittext) like this :

    private final WindowManager mWindowManager;
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    WindowManager.LayoutParams lp = createLayoutParams();
    mWindowManager.addView(view, lp);

so how to make the popup connected to the editText in front of everything ?

This question can also maybe help a little (about z-order of window view): How work the z-order of view (ie: window) added via WindowManager?


回答1:


This is expected, if you see the documentation of DecorView, It give you the background of current view.

What you are doing is starting the action bar on the decorview, hence its coming in background. Read this article for more detail http://www.curious-creature.com/2009/03/04/speed-up-your-android-ui/

To solve this issue, you need to get the current view, for which you may use View focusedView = (View) yourParentView.getFocusedChild();




回答2:


It's may help you, try it.

The key answer is android:windowActionModeOverlay

in res/style.xml define a new theme extends your original theme:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Black.NoTitleBar.ActionModeOverlay"
  parent="android:Theme.Black.NoTitleBar">
    <item name="android:windowActionModeOverlay">true</item>
  </style>
</resources>

or just add a line true in your theme if you have already defined one.

Make your Activity use the theme defined above in AndroidManifest.xml:

<activity
    android:name="you.AppActivity"
    android:theme="@style/ActionModeOverlay" >



回答3:


Try WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

instead of WindowManager.LayoutParams.TYPE_APPLICATION;




回答4:


Their is actually no way to order (z-order) windows added via windowmanager. The only way is to remove the window and to add it back again.



来源:https://stackoverflow.com/questions/39561133/why-my-edittext-copy-paste-menu-is-under-the-edittext-how-change-the-z-order-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!