【Android】优化SystemUI下拉状态栏时图标的隐藏与显示

文章描述了如何在Android系统的CollapsedStatusBarFragment.java文件中修改代码,以实现下拉状态栏时home键、back键、recent键、hidebar及自定义图标隐藏的功能。通过onViewCreated和disable方法控制图标的显示与隐藏,并提供了hideStatusBarKeys和showStatusBarKeys方法来执行动画效果。
摘要由CSDN通过智能技术生成

问题

下拉状态栏时,home键、back键、recent键、hidebar以及自定义图标不会进行隐藏,仍旧出现在下拉状态栏的两侧

涉及文件:
CollapsedStatusBarFragment.java
代码地址:
SystemUI\src\com\android\systemui\statusbar\phone\CollapsedStatusBarFragment.java

原生基础上进行修改

onViewCreated中获取图标,比如home键、back键以及recent按键,安卓原生没有对其进行处理,只对clock进行了处理

@Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
          mStatusBar = (PhoneStatusBarView) view;
          if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_PANEL_STATE)) {
              mStatusBar.restoreHierarchyState(
                      savedInstanceState.getSparseParcelableArray(EXTRA_PANEL_STATE));
          }
          mDarkIconManager = new DarkIconManager(view.findViewById(R.id.statusIcons));
          mDarkIconManager.setShouldLog(true);
          Dependency.get(StatusBarIconController.class).addIconGroup(mDarkIconManager);
          mSystemIconArea = mStatusBar.findViewById(R.id.system_icon_area);
          mClockView = mStatusBar.findViewById(R.id.clock);
          //add view for home back recent and hidebtn start
          mKeyHome = mStatusBar.findViewById(R.id.home);
          mKeyBack = mStatusBar.findViewById(R.id.back);
          mKeyRecent = mStatusBar.findViewById(R.id.recent);
          mKeyHideStatus = mStatusBar.findViewById(R.id.hide_bar);
          //add view for home back recent and hidebtn end
          showSystemIconArea(false);
          showClock(false);
          initEmergencyCryptkeeperText();
          initOperatorName();
      }

disable中进行图标的显示和隐藏

@Override
      public void disable(int displayId, int state1, int state2, boolean animate) {
          if (displayId != getContext().getDisplayId()) {
              return;
          }
          state1 = adjustDisableFlags(state1);
          final int old1 = mDisabled1;
          final int diff1 = state1 ^ old1;
          mDisabled1 = state1;
          if ((diff1 & DISABLE_SYSTEM_INFO) != 0) {
              if ((state1 & DISABLE_SYSTEM_INFO) != 0) {
                  hideSystemIconArea(animate);
                  //add for hiding status bar icon start
                  hideStatusBarKeys(animate);
                  //add for hiding status bar icon end
                  hideOperatorName(animate);
              } else {
                  showSystemIconArea(animate);
                  //add for showing status bar icon start
                  showStatusBarKeys(animate);
                  //add for showing status bar icon end
                  showOperatorName(animate);
              }
          }
          ...
      }

增加隐藏显示方法

隐藏

public void hideStatusBarKeys(boolean animate) {
        if (mKeyHome != null) {
            animateHide(mKeyHome, animate);
            animateHide(mKeyBack, animate);
            animateHide(mKeyRecent, animate);
			animateHide(mKeyHideStatus, animate);
			
        }
    }

显示

public void showStatusBarKeys(boolean animate) {
        if (mKeyHome != null) {
            animateShow(mKeyHome, animate);
            animateShow(mKeyBack, animate);
            animateShow(mKeyRecent, animate);
			animateShow(mKeyHideStatus, animate);
        }
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值