android10 隱藏SystemUI鎖屏下的多用戶圖標的示例代碼

在這裡插入圖片描述

需求:如上圖,需要隱藏右上角的多用戶藍色圖標.
修改後結果如下:

在這裡插入圖片描述

鎖屏相關的佈局在SystemUI

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java

//更新多用戶圖標的可見性
  private void updateVisibilities() {
    if (mMultiUserSwitch.getParent() != mStatusIconArea && !mKeyguardUserSwitcherShowing) {
      if (mMultiUserSwitch.getParent() != null) {
        getOverlay().remove(mMultiUserSwitch);
      }
      mStatusIconArea.addView(mMultiUserSwitch, 0);
    } else if (mMultiUserSwitch.getParent() == mStatusIconArea && mKeyguardUserSwitcherShowing) {
      mStatusIconArea.removeView(mMultiUserSwitch);
    }
    if (mKeyguardUserSwitcher == null) {
      // If we have no keyguard switcher, the screen width is under 600dp. In this case,
      // we only show the multi-user switch if it's enabled through UserManager as well as
      // by the user.
      //控制其顯示還是不顯示
      if (mMultiUserSwitch.isMultiUserEnabled()) {
        mMultiUserSwitch.setVisibility(View.VISIBLE);
      } else {
        mMultiUserSwitch.setVisibility(View.GONE);
      }
    }
    //直接使其不顯示就可以生效
    mMultiUserSwitch.setVisibility(View.GONE);
    mBatteryView.setForceShowPercent(mBatteryCharging && mShowPercentAvailable);
  }

mMultiUserSwitch就是顯示多用戶的控件,對應的代碼在
frameworks/base/packages/SystemUI/res/layout/keyguard_status_bar.xml

 <com.android.systemui.statusbar.phone.MultiUserSwitch android:id="@+id/multi_user_switch"
      android:layout_width="@dimen/multi_user_switch_width_keyguard"
      android:layout_height="match_parent"
      android:background="@drawable/ripple_drawable"
      android:layout_marginEnd="@dimen/multi_user_switch_keyguard_margin">
      <ImageView android:id="@+id/multi_user_avatar"
        android:layout_width="@dimen/multi_user_avatar_keyguard_size"
        android:layout_height="@dimen/multi_user_avatar_keyguard_size"
        android:layout_gravity="center"
        android:scaleType="centerInside"/>
    </com.android.systemui.statusbar.phone.MultiUserSwitch>

讀者可自行查看,完畢~

到此這篇關於android10 隱藏SystemUI鎖屏下的多用戶圖標的文章就介紹到這瞭,更多相關android10 隱藏多用戶圖標內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: