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

4

15

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)

also something a little strange, the popup generate by the last EditText will be

enter image description here

enter image description here

enter image description here

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?

Containment answered 18/9, 2016 at 18:23 Comment(14)
change the background of your floating toolbar to Color.WHITE instead of transparent.Skim
thanks ishita, but how to do this ?Containment
Sorry, but that might not be the problem. Are you calling startActionMode() anywhere in your code? If so, what is the type you're passing to it? You need to setType(ActionMode.TYPE_FLOATING) for the ActionMode to be considered a floating toolbar. Are you using the correct type?Skim
yes, i call it only from MyEditText @override public ActionMode startActionMode(ActionMode.Callback callback, int type) { ... } with ActionMode.TYPE_FLOATING off course (else you will not even see the actionbar close to the edittextContainment
Post the layout XML. Did you add elevation to any widget?Partridgeberry
i do not have any layout xml because i create all the container view and the edittext programmaticaly. I show via windowmanager.addview a linearLayout that contain an EdittextContainment
"so how to make the popup connected to the editText in front of everything ?" -- you have a popup connected to nothing, AFAICT. Why are you working with WindowManager directly, rather than using the various options like PopupWindow or ListPopupWindow?Latonialatoniah
No the popup (for exemple the keyword suggestion) is connected to the window it's EditText belong (because this popup have type= TYPE_APPLICATION_PANEL) and the copy/past menu is connected to the decorview. i need this because my main window is draw directly by an openGL software and any views / controls that i add on it are not drawed :( so i must use other window on the top of it to show an EditText (for exemple). yes i can use popupWindow, but the problem will be exactly the same at the endContainment
So what u want is the popup have to be above the other EditText and under the keyboard ? Which of the three EditTexts is added to the WindowManager ? Third one only ?Jacobson
@TinTran I want the popup above all the EditText and above the keyboard of course ;) all the editTexts have been added to the WindowManager (so i have 2 window)Containment
You can add two EditTexts to a LinearLayout and then add to the WindowManager ? Will that solve the popup above all the EditText ?Jacobson
no really, because the space between the edit must be focusable by the main window (ie if i click between the 2 edit it's must be like if i click on the main window)Containment
If you are target the above lollipop have you try elevation property of view.?Caryloncaryn
yes, it's no help :( i need to elevate the window insteadContainment
M
3

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();

Mankind answered 27/9, 2016 at 2:19 Comment(2)
thanks Ashih, but how to stat the floating actionbar on the current view? because as you saw startactionmode on the current view (ie: the edittext) don't work, this why i was force to call startactionmode from the decorview ..Containment
What do you mean , are you not able to call getActivity().startActionMode(mActionModeCallback);Mankind
C
3

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" >
Clegg answered 29/9, 2016 at 6:1 Comment(4)
no it's didn't help :( in fact in marshmallow it's not anymore static actionbar on the top, but "floating" actionbar.Containment
ohh than i will try to give you a better solution.Clegg
@Loki You can try this: As you already noticed, using reflection is one of the ways. I'm pretty sure that it's the only one. If you're interested in what I did with that menu, check out Carbon. Its EditText does pretty much what you need, but with reflection as well. The code snippet is way too long to paste it here, but here are the links: github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/… plus.google.com/109054799904873578131/posts/BH6r9J5gnw6Clegg
thanks jasmin, but i don't understand when i look the code github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/… where they work with the copy/past menu ? because it's look like they work only on the design of the edittext (like corners, elevation, etc..)Containment
W
0

Try WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

instead of WindowManager.LayoutParams.TYPE_APPLICATION;

Wifely answered 1/6, 2017 at 11:44 Comment(1)
no, unfortunately ... because i will simply have the same problem to make the z-order among several window with TYPE_SYSTEM_ALERT (instead of TYPE_APPLICATION that i have now). NOTE: you can not change the type of the window after the window is createdContainment
P
0

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.

Palaeobotany answered 4/6, 2017 at 14:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.