当前位置:网站首页>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,所以要结合方法三使用
边栏推荐
- 【VSCode】一文详解vscode下安装vim后无法使用Ctrl+CV复制粘贴 使用Vim插件的配置记录
- 绩效考核带给员工的不能只是压力
- 如何让 WPF 程序更好地适配 UI 自动化
- Systemui qsSetting添加新图标
- String是引用类型
- Diffusion Models:生成扩散模型
- 使用COLMAP初步三维重建
- Two years of independent development experience Programmers tell us the experience of making money (listen to the masters who really make money)
- 什么是 DevOps?看这一篇就够了!
- MySQL - Explain explanation
猜你喜欢
推荐一款优秀的通用管理后台
什么是 DevOps?看这一篇就够了!
Chinese valentine's day of young people crazy to make money, earn 140000 a week
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享
"Lonely Walking on the Moon" is a powerful medicine, it can't cure the internal friction of happy twist
数据中台建设(九):数据中台资产运营机制
A comprehensive understanding of MOS tubes, an article is enough
5 cloud security management strategies enterprises should implement
Tarjan 求有向图的强连通分量
他是“中台”之父,凭一个概念为阿里狂赚百亿
随机推荐
Django框架MySQL数据库到models模型的映射关系
分布式链路追踪Jaeger + 微服务Pig在Rainbond上的实践分享
数据中台建设(九):数据中台资产运营机制
双目立体视觉学习笔记(一)
接到“网站动态换主题”的需求,我是如何踩坑的
ReentrantLock 原理
du命令_set命令选项
Escape character is ‘^]’什么意思?怎么使用telnet
开发小程序插件如何实现盈利?
MySQL - Explain详解
Motion Regulations (18) - and check the basic questions - gang
如何治理资源浪费?百度云原生成本优化最佳实践
两个数组中用第二个数组的Value对比换第一个数组中的Key
获取本机IP地址的脚本
图像分割方法
Analysis and comparison of mobile cross-end technical solutions
炫酷又高效的数据可视化大屏,做起来真的没那么难!丨极客星球
Linux-Docker-Mysql安装
绩效考核带给员工的不能只是压力
企业应当实施的5个云安全管理策略