Android软菜单与屏幕重叠
我有一个相对的图标和底部的浮动按钮。问题在于,在api 21或以上的设备中,软菜单与绿色按钮重叠,只能看到半个按钮。其他设备不会出现这种情况Android软菜单与屏幕重叠,android,material-design,nexus-5,Android,Material Design,Nexus 5,我有一个相对的图标和底部的浮动按钮。问题在于,在api 21或以上的设备中,软菜单与绿色按钮重叠,只能看到半个按钮。其他设备不会出现这种情况 我终于找到了解决办法!将此添加到values-v21目录中的themes.xml: false唯一对我有效的方法是将fitsSystemWindows添加到全局主题样式中: <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
我终于找到了解决办法!将此添加到values-v21目录中的
themes.xml
:
false
唯一对我有效的方法是将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">
...
...
获取导航栏高度,并在setContentView之后的OnCreate()中将padding bottom设置为活动的根布局
.....
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;
}
。。。。。
int navHeight=getNavHeight();
如果(导航高度>0){
(findViewById(R.id.rlMain)).setPadding(0,0,0,navHeight);
}
.....
私有int getNavHeight(){
if(Build.VERSION.SDK_INT0){
布尔值hasMenuKey=ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();
布尔hasBackKey=KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE\u BACK);
如果(!hasMenuKey&&!hasBackKey){
返回resources.getDimensionPixelSize(resourceId);
}
}
}捕获(例外情况除外){
返回0;
}
返回0;
}
请发布更多信息,如您正在使用的主题。theme.AppCompat.Light.DarkActionBar(支持库)。因此,它有一个操作栏和选项卡。这将从活动中删除状态栏颜色。