簡體   English   中英

如何重疊系統底部導航欄。

[英]How to overlap system 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;
            }
        }         

使用此代碼我不能重疊導航,它在我的活動視圖底部顯示新的自定義視圖,但不能與自定義視圖重疊導航欄。

任何人都可以幫我這個,用自定義視圖重疊導航欄。

實際上有一些解決方案。由於市場中有沒有硬件按鈕的設備,因此無法重疊使其完全消失。 但是,您可以相應地優雅地排列您的布局。

例如,在 dir中將它添加到styles.xml (v21):

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

或者如果它不起作用,

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

我有一個FrameLayout,您可以將它用於任何布局。 SetMargins在示例中增加了余量。 如果沒有硬件后退和菜單按鈕,它假定系統欄就在那里。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM