application content goes behind the navigation bar in android L
如您所见,我的"了解"按钮位于导航栏的后面。无法修复!!!我试过
1 | <item name="android:fitsSystemWindows">true</item> |
以及在布局文件中进行设置。
我在value-21中的主题是:
1 2 3 4 5 6 7 | <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar"> <item name="android:windowNoTitle">true</item> <item name="android:windowActionBar">false</item> <item name="android:windowFullscreen">false</item> <item name="android:windowContentOverlay">@null</item> <item name="android:fitsSystemWindows">true</item> </style> |
整个应用程序中所有屏幕的情况相同。
请帮助。
这是解决方案。
大多数布局都可以通过在values-v21 style.xml
中添加这些属性来解决
1 2 3 | <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> <item name="android:fitsSystemWindows">true</item> |
对于其他人,我已经计算了导航栏的高度,并向视图添加了边距。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public static int getSoftButtonsBarSizePort(Activity activity) { // getRealMetrics is only available with API 17 and + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int usableHeight = metrics.heightPixels; activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics); int realHeight = metrics.heightPixels; if (realHeight > usableHeight) return realHeight - usableHeight; else return 0; } return 0; } |
注意:通过使用上述解决方案,一切正常,但是我也在我的应用程序中使用了PopupWindow.PopupWindow的布局在android L中变得混乱。在这里查找问题和解决方案
这是如此简单,
只需将此行添加到您的父布局xml:
1 | android:fitsSystemWindows="true" |
为获得良好的用户体验,您无需使用
来阻止导航键区域
这是一个更好的解决方案,如果您使用的是ResideMenu库,则只需在ResideMenu.java
中添加此方法即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | @Override protected boolean fitSystemWindows(Rect insets) { int bottomPadding = insets.bottom; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Resources resources = getResources(); int resourceId = resources.getIdentifier("navigation_bar_height","dimen","android"); if (resourceId > 0) { bottomPadding += resources.getDimensionPixelSize(resourceId); } } this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top, viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + bottomPadding); insets.left = insets.top = insets.right = insets.bottom = 0; return true; } |
,如果您使用的是
1 | menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); |
希望它可以节省您的时间
在您的
1 2 3 4 5 6 | ViewCompat.setOnApplyWindowInsetsListener( findViewById(android.R.id.content), (v, insets) -> { ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams(); params.bottomMargin = insets.getSystemWindowInsetBottom(); return insets.consumeSystemWindowInsets(); }); |
当布局具有此标志时,表示此布局要求系统应用窗口插入。在我们的例子中,这意味着FrameLayout希望应用等于状态栏高度的填充。
在设置内容视图时,只需在Activity \\的onCreate()中进行设置:
1 2 3 4 | int mScreenWidth = getWindowManager().getDefaultDisplay().getWidth(); int mScreenHeight = getWindowManager().getDefaultDisplay().getHeight(); View view = getLayoutInflater().inflate(R.layout.activity_main, null); setContentView(view, new ViewGroup.LayoutParams(mScreenWidth, mScreenHeight)); |
我在上面尝试了许多答案,但是没有一个对我有用。我已经package了相对布局,在该布局中,我的按钮(必须连接到底部)位于另一个线性布局中。它神奇地为我工作。
如果有人可以添加原因,这会有所帮助。
在大多数情况下,默认情况下,导航栏应始终位于应用程序下方,除非您已触发设置。
如果这是您想要的行为,请确保您未运行以下行:
1 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); |
在您的java的setcontent视图之前尝试一下,此问题解决了我的问题。
1 2 3 | requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);` |
将