Android 导航栏功能项的显示与屏蔽

 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>

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Brave & Real

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值