为什么我的EditText复制/粘贴菜单位于EditText下?如何更改弹出窗口的z顺序? [英] Why my EditText copy/paste menu is under the EditText? How change the z-order of popup window?

查看:127
本文介绍了为什么我的EditText复制/粘贴菜单位于EditText下?如何更改弹出窗口的z顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意

如果有人知道如何订购通过windowmanager添加的Windows(z顺序),我也将接受答案,因为它将回答所有问题.实际上,我只发现在windowManager.addView(MyView)之后立即执行windowManager.removeView(MyView)将视图置于另一个视图的前面,但这并不理想,因为它在视觉上删除并添加了视图.如此疯狂的想法是,他们没有在android中内置函数来进行如此简单的思考.


我创建一个包含EditText的视图(linearlayout).我通过WindowManager.addView(视图,Layout_Params)在活动中添加该视图;

但是我有一个问题,即编辑文本将生成的每个弹出窗口(如复制/粘贴菜单或单词建议菜单)都将位于其他视图下,甚至在其自己的EditText视图下(不在图片上,该编辑文本都具有透明背景)

我使用这些布局参数创建视图(即LinearLayout):

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;
}

我显示了这样的视图(仅包含一个edittext):

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

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

那么如何使弹出窗口连接到一切前面的editText?

这个问题也许也可以有所帮助(关于窗口视图的z顺序):解决方案

尝试一下可能会对您有所帮助.

关键答案是 android:windowActionModeOverlay

在res/style.xml中定义一个新主题来扩展您的原始主题:

<?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>

,或者如果已定义主题,则只需在主题中添加true.

使您的活动"使用上面在AndroidManifest.xml中定义的主题:

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

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?

解决方案

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" >

这篇关于为什么我的EditText复制/粘贴菜单位于EditText下?如何更改弹出窗口的z顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆