Android 10 SystemUI 如何添加4G信号和WiFi图标

代码路径:
frameworks/base/packages/SystemUI/res/layout/system_icons.xml
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java
在system_icons.xml文件中,BatteryMeterView 主要是处理电量UI显示,StatusIconContainer 主要是处理wifi和4GUI显示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:systemui="http://schemas.android.com/apk/res-auto"
    android:id="@+id/system_icons"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical">

    <com.android.systemui.statusbar.phone.StatusIconContainer android:id="@+id/statusIcons"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:paddingEnd="@dimen/signal_cluster_battery_padding"
        android:gravity="center_vertical"
        android:orientation="horizontal"/>

    <com.android.systemui.BatteryMeterView android:id="@+id/battery"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:clipToPadding="false"
        android:clipChildren="false"
        systemui:textAppearance="@style/TextAppearance.StatusBar.Clock" />
</LinearLayout>

在CollapsedStatusBarFragment.java文件中onViewCreated方法中statusIcons就是添加添加状态栏wifi图标和4G图标

@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));
    }
  //start  这里就是添加状态栏wifi图标和4G图标
    mDarkIconManager = new DarkIconManager(view.findViewById(R.id.statusIcons));
    mDarkIconManager.setShouldLog(true);
    Dependency.get(StatusBarIconController.class).addIconGroup(mDarkIconManager);
   //end
     mSystemIconArea = mStatusBar.findViewById(R.id.system_icon_area);
    mClockView = mStatusBar.findViewById(R.id.clock);
    showSystemIconArea(false);
    showClock(false);
    initEmergencyCryptkeeperText();
    initOperatorName();
}

在CollapsedStatusBarFragment.java文件中onDestroyView()方法中移除wifi图标和4G图标

@Override
public void onDestroyView() {
    super.onDestroyView();
    //start 这里就是移除wifi图标和4G图标
    Dependency.get(StatusBarIconController.class).removeIconGroup(mDarkIconManager);
    //end
    if (mNetworkController.hasEmergencyCryptKeeperText()) {
        mNetworkController.removeCallback(mSignalCallback);
    }
}
上一篇:长时间待机的监控摄像机可以持续多久


下一篇:移动工业时代没有聚合路由器怎么行?