当前位置:网站首页>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,所以要结合方法三使用
边栏推荐
猜你喜欢

Focus!2022 interview must brush 461 interview questions summary + interview + resume template

划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板

移动跨端技术方案分析对比

视觉SLAM十四讲学习笔记 第7讲 视觉里程计

5 cloud security management strategies enterprises should implement

What is DevOps?Enough to read this one!

双目立体视觉笔记(三)三角测量、极线校正

七夕疯狂搞钱的年轻人,一周赚14万

ReentrantLock 原理

炫酷又高效的数据可视化大屏,做起来真的没那么难!丨极客星球
随机推荐
持续交付(四)Jenkins多线程任务执行
使用COLMAP初步三维重建
新消费、出海、大健康......电子烟寻找“避风港”
图像分割方法
LeetCode每日一题(858. Mirror Reflection)
两年独立开发经验程序员告诉我们赚钱的经验(听听真正赚到钱的高手做法)
FHQ-Treap 简介
Linux-Docker-Mysql安装
情人节浪漫3D照片墙【附源码】
03 多线程与高并发 - ReentrantLock 源码解析
抽奖/秒杀/竞价/评分/权威/投票,技术教你用合适的方法做好活动
Do you understand the various configurations in the project?
【软考 系统架构设计师】软件架构设计② 软件架构风格
直击面试!阿里金九银十最新面试小册 稳过!
【Game Of AutoTest】1、再度启程,重识游戏自动化测试
程序猿七夕礼物-如何30分钟给女朋友快速搭建专属语聊房
视觉SLAM十四讲学习笔记 第7讲 视觉里程计
Diffusion Models:生成扩散模型
从零开始配置 vim(7)——自动命令
TensorFlow学习记录(三):高阶操作 & 神经网络与全连接层