Android软菜单重叠屏幕

时间:2015-07-05 01:41:40

标签: android material-design nexus-5

我在底部有一个RelativeLayout和一个浮动按钮。问题是在api 21或更高版本的设备中,软菜单与绿色按钮重叠,只看到半按钮。其他设备不会出现这种情况。

enter image description here

3 个答案:

答案 0 :(得分:2)

最后我得到了解决方案!将其添加到您的themes.xml,其值为v21目录:

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

答案 1 :(得分:0)

唯一对我有用的是将fitsSystemWindows添加到全局主题样式中:

    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:fitsSystemWindows">true</item>
    </style>

在AndroidManifest.xml中:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name=".App">
    ...

答案 2 :(得分:0)

获取导航栏高度,并在setContentView之后将填充底部设置为OnCreate()中活动的根布局。

.....
        int navHeight = getNavHeight();
        if (navHeight > 0) {
            (findViewById(R.id.rlMain)).setPadding(0, 0, 0, navHeight);
        }
.....

    private int getNavHeight() {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
            return 0;
        try {

            Resources resources = getResources();
            int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0) {
                boolean hasMenuKey = ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();
                boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);

                if (!hasMenuKey && !hasBackKey) {
                    return resources.getDimensionPixelSize(resourceId);
                }
            }
        } catch (Exception ex) {
            return 0;
        }
        return 0;
    }