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?

zeus
  • 12,173
  • 9
  • 63
  • 184
  • change the background of your floating toolbar to `Color.WHITE` instead of transparent. – Ishita Sinha Sep 24 '16 at 11:41
  • thanks ishita, but how to do this ? – zeus Sep 24 '16 at 14:00
  • 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? – Ishita Sinha Sep 24 '16 at 15:36
  • 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 edittext – zeus Sep 24 '16 at 20:30
  • Post the layout XML. Did you add elevation to any widget? – Eugen Pechanec Sep 27 '16 at 19:47
  • 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 Edittext – zeus Sep 27 '16 at 21:13
  • "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`? – CommonsWare May 29 '17 at 19:32
  • 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 end – zeus May 29 '17 at 19:39
  • So what u want is the popup have to be above the other EditText and under the keyboard ? Which of the three `EditText`s is added to the `WindowManager` ? Third one only ? – Tin Tran May 31 '17 at 15:30
  • @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) – zeus May 31 '17 at 16:09
  • You can add two EditTexts to a LinearLayout and then add to the WindowManager ? Will that solve the `popup above all the EditText` ? – Tin Tran May 31 '17 at 16:15
  • 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) – zeus May 31 '17 at 17:04
  • If you are target the above lollipop have you try elevation property of view.? – Moinkhan Jun 02 '17 at 08:51
  • yes, it's no help :( i need to elevate the window instead – zeus Jun 02 '17 at 13:13

4 Answers4

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

Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17
  • 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 .. – zeus Sep 27 '16 at 08:07
  • What do you mean , are you not able to call getActivity().startActionMode(mActionModeCallback); – Ashish Rawat Sep 30 '16 at 18:37
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" >
Jamil Hasnine Tamim
  • 4,389
  • 27
  • 43
  • no it's didn't help :( in fact in marshmallow it's not anymore static actionbar on the top, but "floating" actionbar. – zeus Sep 29 '16 at 08:06
  • ohh than i will try to give you a better solution. – Jamil Hasnine Tamim Sep 29 '16 at 08:08
  • @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: https://github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/carbon/widget/EditText.java https://plus.google.com/109054799904873578131/posts/BH6r9J5gnw6 – Jamil Hasnine Tamim Sep 29 '16 at 08:11
  • thanks jasmin, but i don't understand when i look the code https://github.com/ZieIony/Carbon/blob/master/carbon/src/main/java/carbon/widget/EditText.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..) – zeus Sep 29 '16 at 10:10
0

Try WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

instead of WindowManager.LayoutParams.TYPE_APPLICATION;

Shubham Goel
  • 1,962
  • 17
  • 25
  • 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 created – zeus Jun 01 '17 at 12:10
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.