網站首頁 編程語言 正文
?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
相關推薦
- 2023-01-01 C語言實現輸出各種三角形_C 語言
- 2022-07-09 kubernetes之資源限制
- 2022-04-25 基于NPOI用C#開發的Excel以及表格設置_C#教程
- 2022-08-15 C語言實現字符串的部分匹配算法
- 2024-02-26 Yaml數據讀取
- 2022-11-30 C語言實現單鏈表的基本操作分享_C 語言
- 2023-01-21 Python參數解析器configparser簡介_python
- 2022-05-29 C語言?超詳細模擬實現單鏈表的基本操作建議收藏_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支