如何实现Android导航栏功能项的显示与屏蔽

如何实现Android导航栏功能项的显示与屏蔽

这篇文章给大家分享的是有关如何实现Android导航栏功能项的显示与屏蔽的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

Android 的导航栏有诸多功能,例入 截屏,音量加,音量减,最近任务,菜单.返回,主页面,输入法开关 ......

如何实现Android导航栏功能项的显示与屏蔽

代码源路径:frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\NavigationBarView.java

publicButtonDispatchergetScreenshotButton(){returnmButtonDispatchers.get(R.id.screenshot);}publicButtonDispatchergetVolumeAddButton(){returnmButtonDispatchers.get(R.id.volume_add);}publicButtonDispatchergetVolumeSubButton(){returnmButtonDispatchers.get(R.id.volume_sub);}publicButtonDispatchergetRecentsButton(){returnmButtonDispatchers.get(R.id.recent_apps);}publicButtonDispatchergetMenuButton(){returnmButtonDispatchers.get(R.id.menu);}publicButtonDispatchergetBackButton(){returnmButtonDispatchers.get(R.id.back);}publicButtonDispatchergetHomeButton(){returnmButtonDispatchers.get(R.id.home);}publicButtonDispatchergetImeSwitchButton(){returnmButtonDispatchers.get(R.id.ime_switcher);}publicButtonDispatchergetAccessibilityButton(){returnmButtonDispatchers.get(R.id.accessibility_button);}

Android 即在此类中完成对 Button图标 的选择 .

若需要展示/隐藏对应的 功能选项时,需要在此处修改:

privatevoidprepareNavigationBarView(){mNavigationBarView.reorient();ButtonDispatcherrecentsButton=mNavigationBarView.getRecentsButton();recentsButton.setOnClickListener(this::onRecentsClick);recentsButton.setOnTouchListener(this::onRecentsTouch);recentsButton.setLongClickable(true);recentsButton.setOnLongClickListener(this::onLongPressBackRecents);ButtonDispatcherbackButton=mNavigationBarView.getBackButton();backButton.setLongClickable(true);backButton.setOnLongClickListener(this::onLongPressBackRecents);ButtonDispatcherhomeButton=mNavigationBarView.getHomeButton();homeButton.setOnTouchListener(this::onHomeTouch);homeButton.setOnLongClickListener(this::onHomeLongClick);ButtonDispatcheraccessibilityButton=mNavigationBarView.getAccessibilityButton();accessibilityButton.setOnClickListener(this::onAccessibilityClick);accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);updateAccessibilityServicesState(mAccessibilityManager);ButtonDispatcherscreenshotButton=mNavigationBarView.getScreenshotButton();screenshotButton.setOnClickListener(this::screenshotClick);screenshotButton.setOnTouchListener(this::screenshotTouch);booleanisShow=Settings.System.getInt(getContext().getContentResolver(),Settings.System.SCREENSHOT_BUTTON_SHOW,1)==1;if(isShow){screenshotButton.setVisibility(View.VISIBLE);}else{screenshotButton.setVisibility(View.GONE);}ButtonDispatchervolumeAddButton=mNavigationBarView.getVolumeAddButton();ButtonDispatchervolumeSubButton=mNavigationBarView.getVolumeSubButton();booleanisShowVolumeButton="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

<stringname="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

<!--Heightofthestatusbar--><dimenname="status_bar_height">0dp</dimen>

感谢各位的阅读!关于“如何实现Android导航栏功能项的显示与屏蔽”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

发布于 2021-12-22 21:56:30
收藏
分享
海报
0 条评论
53
上一篇:python中如何定义栈、队列及双端队列 下一篇:java如何实现文件切片上传服务器+断点续传
目录

    0 条评论

    本站已关闭游客评论,请登录或者注册后再评论吧~

    忘记密码?

    图形验证码