应用程序内容在 android L 中位于导航栏后面

application content goes behind the navigation bar in android L

如您所见,我的 "Got It" 按钮在导航后面 bar.Not 可以修复它!!!我试过了

<item name="android:fitsSystemWindows">true</item>  

以及在布局文件中设置。

我在 value-21 中的主题是:

 <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

<item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:fitsSystemWindows">true</item>

对于其他人,我已经计算了导航栏的高度并为我的视图添加了边距。

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

注意: 通过使用上述解决方案一切正常,但我也在我的 app.The 中使用 PopupWindow PopupWindow 的布局在 android 中搞砸了L. 查找问题和解决方案

popupWindowsoftInputMode 设置为 SOFT_INPUT_ADJUST_RESIZE 可解决问题。

只需在 Activity 的 onCreate() 中进行设置,同时设置内容视图:

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

为了良好的用户体验,您不需要使用 android:windowTranslucentNavigation

来屏蔽导航键区域

这是更好的解决方案,如果您使用的是 ResideMenu 库,则只需在 ResideMenu.java

中添加此方法
  @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;
}

如果您使用的是 SlidingMenu 库,则通过以下方式将 mod 更改为 SLIDING_CONTENT

menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

希望它能节省您的时间

Activity 的 onCreate 方法中使用此代码(如果您有 BaseActivity,您可以在那里执行此操作,以便所有活动都应用此代码):

ViewCompat.setOnApplyWindowInsetsListener(
            findViewById(android.R.id.content), (v, insets) -> {
                ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
                params.bottomMargin = insets.getSystemWindowInsetBottom();
                return insets.consumeSystemWindowInsets();
            });

当布局有此标志时,表示此布局要求系统应用 window 内嵌。在我们的例子中,这意味着 FrameLayout 希望应用一个等于状态栏高度的填充。

就是这么简单, 只需将此行添加到您的父布局 xml:

android:fitsSystemWindows="true"

我尝试了上面的许多答案,但其中 none 对我有用。我已经将我的按钮(必须附加到底部)的相对布局包装在另一个线性布局中。它神奇地为我工作。

如果有人能补充一下原因,那会更有帮助。

在 java 的 setcontent 视图之前尝试这个,我的问题已经解决了这个`

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);`

在大多数情况下,根据默认,导航栏应始终低于 应用程序,除非您已触发设置。

如果这是您想要确保自己不是运行这一行的行为:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);