您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)如何實現(xiàn)Android導航欄功能項的顯示與屏蔽的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
Android 的導航欄有諸多功能,例入 截屏,音量加,音量減,最近任務(wù),菜單.返回,主頁面,輸入法開關(guān) ......
代碼源路徑: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圖標 的選擇 .
若需要展示/隱藏對應(yīng)的 功能選項時,需要在此處修改:
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); } }
可以將對應(yīng)的Button 設(shè)置 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的顯示順序 .
提一嘴,如果需要用到屏蔽狀態(tài)欄以及任務(wù)欄,可以將如下status_bar_height 的高度設(shè)為0.
frameworks\base\core\res\res\values\dimens.xml
<!-- Height of the status bar --> <dimen name="status_bar_height">0dp</dimen>
感謝各位的閱讀!關(guān)于“如何實現(xiàn)Android導航欄功能項的顯示與屏蔽”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。