状态栏"/>
Android 导航栏、状态栏
1.setSystemUiVisibility(int visibility)
通过setSystemUiVisibility(int visibility)方法,可以改变状态栏或者其他系统UI的可见性。
getWindow().getDecorView().setSystemUiVisibility(int visibility);
可供选择的参数:
①View.SYSTEM_UI_FLAG_VISIBLE
默认模式,显示状态栏和导航栏
②View.SYSTEM_UI_FLAG_LOW_PROFILE
低调模式,隐藏不重要的状态栏图标,导航栏中相应的图标都变成了一个小点。点击状态栏或导航栏还原成正常的状态。
③SYSTEM_UI_FLAG_HIDE_NAVIGATION
隐藏导航栏,点击屏幕任意区域,导航栏将重新出现,并且不会自动消失。
④SYSTEM_UI_FLAG_FULLSCREEN
隐藏状态栏,点击屏幕区域不会出现,需要从状态栏位置下拉才会出现。
⑤SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
将布局内容拓展到导航栏和状态栏的后面。
2.获取状态栏、导航栏高度
①获取顶部状态栏statusBar高度
private int getStatusBarHeight() {
Resources resources = mActivity.getResources();
int resourceId = resources.getIdentifier( "status_bar_height", "dimen","android");
int height = resources.getDimensionPixelSize( resourceId);
Log.v("", "Status height:" + height);
return height;
}
②获取底部导航栏navigationBar高度
private int getNavigationBarHeight() {
Resources resources = mActivity.getResources();
int resourceId = resources.getIdentifier( "navigation_bar_height","dimen", "android");
int height = resources.getDimensionPixelSize( resourceId);
Log.v("", "Navi height:" + height);
return height;
}
③获取设备是否存在NavigationBar
public static boolean checkHasNavigationBar( Context context) {
boolean hasNavigationBar = false;
Resources rs = context.getResources();
int id = rs.getIdentifier( "config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = rs.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke( systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
}
return hasNavigationBar;
}
注:没显示导航栏的,方法二还是会返回导航栏的值,而不是返回0,所以要结合方法三使用
更多推荐
Android 导航栏、状态栏
发布评论