当前位置:网站首页>21天学习挑战赛--第二天打卡(setSystemUiVisibility、导航栏、状态栏)
21天学习挑战赛--第二天打卡(setSystemUiVisibility、导航栏、状态栏)
2022-08-04 12:37:00 【孟芳芳】
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,所以要结合方法三使用
边栏推荐
猜你喜欢
随机推荐
关于mysql join 的一些说明
【软考 系统架构设计师】软件架构设计② 软件架构风格
num_workers
yolo系列的Neck模块
Cool and efficient data visualization big screen, it's really not that difficult to do!丨Geek Planet
ReentrantLock 原理
Do you understand the various configurations in the project?
Motion Regulations (18) - and check the basic questions - gang
数据中台建设(九):数据中台资产运营机制
新消费、出海、大健康......电子烟寻找“避风港”
年轻人为什么不喜欢买蒙牛、伊利了?
博云入选 Gartner 中国 DevOps 代表厂商
程序猿七夕礼物-如何30分钟给女友快速搭建专属语聊房
持续交付(四)Jenkins多线程任务执行
【PHP实现微信公众平台开发—基础篇】第2章 微信公众账号及申请流程详解
接入华为游戏防沉迷,点击防沉迷弹窗后游戏闪退
sqlserver删除重复数据
他是“中台”之父,凭一个概念为阿里狂赚百亿
高手,云集在于REST、gRPC 和 GraphQL之间!
Launcher app prediction









