android - 如何重叠系统底部导航栏。?

标签 android

enter image description here我正在尝试使用窗口管理器重叠系统底部导航栏,但我做不到。我正在使用波纹管代码。我已将重力设置为底部,因此它在我的 Activity View 底部显示 View 层,而不是不与底部导航栏重叠。

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

使用此代码我不能重叠导航,它在我的 Activity View 底部显示新的自定义 View 但不能将导航栏与自定义 View 重叠。

任何人都可以帮我解决这个问题,将导航栏与自定义 View 重叠。?

最佳答案

实际上有一些解决方案。您不能重叠使其完全消失的方法,因为市场上有没有硬件按钮的设备。然而,您可以优雅地相应地安排您的布局。

例如, 将此添加到 styles.xml (v21) 的 values 目录中:

<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 在示例中为按钮添加边距。如果没有硬件返回和菜单按钮,它假定系统栏存在。

关于android - 如何重叠系统底部导航栏。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31534808/

相关文章:

android - jquery 移动数字小键盘 phonegap

java - 如何创建包含非英语项目的抽屉导航?

android - 为什么edittext隐藏在软键盘后面

Android Room Persistence Library Proguard 配置

android - GridLayout(不是GridView)如何均匀拉伸(stretch)所有 child

android - 绘制填充外边界的矩形

android - 在哪里存储下载的图像

java - Android Java奇怪的UCrop权限问题

android - 当路径不存在时,Firebase childEventListener 返回值

java - 显示 AVD 的日志