Android导航栏功能项的显示与屏蔽介绍
作者:Android 时间:2022-09-27 06:38:55
Android 的导航栏有诸多功能,例入 截屏,音量加,音量减,最近任务,菜单.返回,主页面,输入法开关......
代码源路径:frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\NavigationBarView.java
public ButtonDispatcher getScreenshotButton() {
return mButtonDispatchers.get(R.id.screenshot);
}
public ButtonDispatcher getVolumeAddButton() {
return mButtonDispatchers.get(R.id.volume_add);
}
public ButtonDispatcher getVolumeSubButton() {
return mButtonDispatchers.get(R.id.volume_sub);
}
public ButtonDispatcher getRecentsButton() {
return mButtonDispatchers.get(R.id.recent_apps);
}
public ButtonDispatcher getMenuButton() {
return mButtonDispatchers.get(R.id.menu);
}
public ButtonDispatcher getBackButton() {
return mButtonDispatchers.get(R.id.back);
}
public ButtonDispatcher getHomeButton() {
return mButtonDispatchers.get(R.id.home);
}
public ButtonDispatcher getImeSwitchButton() {
return mButtonDispatchers.get(R.id.ime_switcher);
}
public ButtonDispatcher getAccessibilityButton() {
return mButtonDispatchers.get(R.id.accessibility_button);
}
Android 即在此类中完成对 Button图标 的选择 .
若需要展示/隐藏对应的 功能选项时,需要在此处修改:
private void prepareNavigationBarView() {
mNavigationBarView.reorient();
ButtonDispatcher recentsButton = mNavigationBarView.getRecentsButton();
recentsButton.setOnClickListener(this::onRecentsClick);
recentsButton.setOnTouchListener(this::onRecentsTouch);
recentsButton.setLongClickable(true);
recentsButton.setOnLongClickListener(this::onLongPressBackRecents);
ButtonDispatcher backButton = mNavigationBarView.getBackButton();
backButton.setLongClickable(true);
backButton.setOnLongClickListener(this::onLongPressBackRecents);
ButtonDispatcher homeButton = mNavigationBarView.getHomeButton();
homeButton.setOnTouchListener(this::onHomeTouch);
homeButton.setOnLongClickListener(this::onHomeLongClick);
ButtonDispatcher accessibilityButton = mNavigationBarView.getAccessibilityButton();
accessibilityButton.setOnClickListener(this::onAccessibilityClick);
accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
updateAccessibilityServicesState(mAccessibilityManager);
ButtonDispatcher screenshotButton = mNavigationBarView.getScreenshotButton();
screenshotButton.setOnClickListener(this:: screenshotClick);
screenshotButton.setOnTouchListener(this:: screenshotTouch);
boolean isShow=Settings.System.getInt(getContext().getContentResolver(), Settings.System.SCREENSHOT_BUTTON_SHOW, 1) == 1;
if(isShow){
screenshotButton.setVisibility(View.VISIBLE);
}else{
screenshotButton.setVisibility(View.GONE);
}
ButtonDispatcher volumeAddButton=mNavigationBarView.getVolumeAddButton();
ButtonDispatcher volumeSubButton=mNavigationBarView.getVolumeSubButton();
boolean isShowVolumeButton="true".equals(SystemProperties.get("ro.rk.systembar.voiceicon","true"));
if(isShowVolumeButton){
volumeAddButton.setVisibility(View.VISIBLE);
volumeSubButton.setVisibility(View.VISIBLE);
}else{
volumeAddButton.setVisibility(View.GONE);
volumeSubButton.setVisibility(View.GONE);
}
if (getContext().getResources().getConfiguration().smallestScreenWidthDp < 400) {
volumeAddButton.setVisibility(View.GONE);
volumeSubButton.setVisibility(View.GONE);
}
}
可以将对应的Button 设置 setVisibility(View.GONE / View.INVISIBLE / View.VISIBLE);
当加上setVisibility时,UI界面还没显示时,需要注意config.xml中是否有写进去需要的Button .
frameworks\base\packages\SystemUI\res\values\config.xml
<string name="config_navBarLayout" translatable="false">left;volume_sub,back,home,recent,volume_add;right</string>
需要注意的是,config中配置的顺序 即为 UI的显示顺序 .
提一嘴,如果需要用到屏蔽状态栏以及任务栏,可以将如下status_bar_height的高度设为0.
frameworks\base\core\res\res\values\dimens.xml
<!-- Height of the status bar -->
<dimen name="status_bar_height">0dp</dimen>
来源:https://blog.csdn.net/qq_44844314/article/details/122059496
标签:Android,导航栏
0
投稿
猜你喜欢
c#接口使用示例分享
2022-02-22 17:38:46
VC对自定义资源加密解密(AES)的详解
2023-01-10 00:27:15
利用java开发简易版扫雷游戏
2023-11-07 14:35:15
一篇文章让你彻底了解Java可重入锁和不可重入锁
2023-12-06 11:57:26
Android 4.0 设置全屏修改的解决方法
2022-11-24 17:08:12
.NET实现父窗体关闭而不影响子窗体的方法
2022-10-06 20:56:04
Android搭建grpc环境过程分步详解
2023-02-16 01:41:31
Java下http下载文件客户端和上传文件客户端实例代码
2021-09-09 16:52:11
Android开发input问题解决分析
2021-11-10 08:58:46
c#解压文件的实例方法
2022-04-25 09:49:40
SpringBoot参数校验Validator框架详解
2023-09-22 07:08:40
C#实现左截取和右截取字符串实例
2022-06-06 08:29:39
java 的Collection接口实例详解
2021-09-22 15:35:00
java 画pdf用itext调整表格宽度、自定义各个列宽的方法
2021-07-12 04:16:10
Andriod使用多线程实现轮播图片
2023-07-27 15:47:31
Automapper实现自动映射的实例代码
2023-08-14 16:37:10
Android 自定义圆形带刻度渐变色的进度条样式实例代码
2023-11-23 13:21:38
java web开发之购物车功能实现示例代码
2023-01-24 16:52:55
教你轻松制作Android音乐播放器
2022-09-28 01:19:28
Android开发必知 九种对话框的实现方法
2022-10-23 07:47:26