简体   繁体   中英

How to overlap system bottom navigation bar.?

在此输入图像描述 I am trying to overlap system bottom navigation bar using window manager but i can`t do it. I am Using bellow code.I have set gravity to bottom, therefore it show view layer in bottom of my activity view not not overlapping bottom navigation bar.

public void onCreate(Bundle savedInstancestate)
{
  super.onCreate(savedInstancestate);
  this.requestWindowFeature(Window.FEATURE_NO_TITLE);7

  manager = ((WindowManager)    getApplicationContext().getSystemService(Context.WINDOW_SERVICE));

  localLayoutParams = new WindowManager.LayoutParams();
  localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
  localLayoutParams.gravity = Gravity.BOTTOM;    

  localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|

       // this is to enable the notification to recieve touch events
       //WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |
        //WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |

       // Draws over navigation bar
  WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;


  //localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
  localLayoutParams.height = (int) (50 *     getResources().getDisplayMetrics().scaledDensity);
  localLayoutParams.format = PixelFormat.TRANSPARENT;

  view = new customView(this);

  manager.addView(view, localLayoutParams);

  setContentView(R.layout.Imges);
  }
      public class customView extends ViewGroup {

              public customView(Context context) {
                super(context);
              }

            @Override
            protected void onLayout(boolean changed, int l, int t, int r, int b) {
            }

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                Log.v("customView", "------Intercepted-------");
                return true;
            }
        }         

Using this code i can't overlap navigation,Its shows new custom view in bottom of my activity view but can not overlap navigation bar with custom view.

any one can help me on this, to overlap navigation bar with custom view.?

There are actually some solutions.You cannot overlap in the means of making it totally disappear since there are devices in market without the hardware buttons. However you can elegantly arrange your layout accordingly.

For example, Add this to your styles.xml (v21 )in a values dir:

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

or if it does not work,

boolean hasMenuKey = ViewConfiguration.get(getContext()).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

    if(!hasMenuKey && !hasBackKey) {
        // Do whatever you need to do, this device has a navigation bar
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT
        );
        params.setMargins(0, 0, 0, 75);
        entrancelayout.setLayoutParams(params);
        entrancelayout.requestLayout();
    }

I had a FrameLayout, you can use it for whatever layout you have. SetMargins adds margin to buttom in example. It assumes System Bar is there if there are no hardware back and menu buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM