• systemui状态栏添加新图标


    状态栏右侧添加新图标
    需求描述

    在状态栏右边添加一个自定义图标,根据广播更新图标。

    代码实现

    framework部分修改
    frameworks/base/core/res/res/values/config.xml最上方config_statusBarIcons。原生注释写的很清楚了,用不要钱的翻译翻译一下:
    不要翻译。
    定义右侧图标的插槽。
    也就是状态栏里不是通知的图标
    1、config_statusBarIcons数组里添加自定义图标xiguatong
    2、在下方添加string xiguatong
    frameworks/base/core/res/res/values/config.xml中config_statusBarIcons的顺序表示右侧状态栏图标的顺序,我们在电量图标前面加了一个xiguatong

    
        <string-array name="config_statusBarIcons">
            <item><xliff:g id="id">@string/status_bar_alarm_clockxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_rotatexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_headsetxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_data_saverxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_imexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_sync_failingxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_sync_activexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_nfcxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_ttyxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_speakerphonexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_cdma_erixliff:g>item>
            <item><xliff:g id="id">@string/status_bar_data_connectionxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_phone_evdo_signalxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_phone_signalxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_securexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_bluetoothxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_managed_profilexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_castxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_screen_recordxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_vpnxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_cameraxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_microphonexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_locationxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_mutexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_volumexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_zenxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_ethernetxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_wifixliff:g>item>
            <item><xliff:g id="id">@string/status_bar_hotspotxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_mobilexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_airplanexliff:g>item>
            <item><xliff:g id="id">@string/status_bar_xiguatongxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_batteryxliff:g>item>
            <item><xliff:g id="id">@string/status_bar_sensors_offxliff:g>item>
        string-array>
    	<string translatable="false" name="status_bar_xiguatong">xiguatongstring>
        <string translatable="false" name="status_bar_rotate">rotatestring>
        <string translatable="false" name="status_bar_headset">headsetstring>
        <string translatable="false" name="status_bar_data_saver">data_saverstring>
        <string translatable="false" name="status_bar_managed_profile">managed_profilestring>
        <string translatable="false" name="status_bar_ime">imestring>
        <string translatable="false" name="status_bar_sync_failing">sync_failingstring>
        <string translatable="false" name="status_bar_sync_active">sync_activestring>
        <string translatable="false" name="status_bar_cast">caststring>
        <string translatable="false" name="status_bar_hotspot">hotspotstring>
        <string translatable="false" name="status_bar_location">locationstring>
        <string translatable="false" name="status_bar_bluetooth">bluetoothstring>
        <string translatable="false" name="status_bar_nfc">nfcstring>
        <string translatable="false" name="status_bar_tty">ttystring>
        <string translatable="false" name="status_bar_speakerphone">speakerphonestring>
        <string translatable="false" name="status_bar_zen">zenstring>
        <string translatable="false" name="status_bar_mute">mutestring>
        <string translatable="false" name="status_bar_volume">volumestring>
        <string translatable="false" name="status_bar_wifi">wifistring>
        <string translatable="false" name="status_bar_cdma_eri">cdma_eristring>
        <string translatable="false" name="status_bar_data_connection">data_connectionstring>
        <string translatable="false" name="status_bar_phone_evdo_signal">phone_evdo_signalstring>
        <string translatable="false" name="status_bar_phone_signal">phone_signalstring>
        <string translatable="false" name="status_bar_battery">batterystring>
        <string translatable="false" name="status_bar_alarm_clock">alarm_clockstring>
        <string translatable="false" name="status_bar_secure">securestring>
        <string translatable="false" name="status_bar_clock">clockstring>
        <string translatable="false" name="status_bar_mobile">mobilestring>
        <string translatable="false" name="status_bar_vpn">vpnstring>
        <string translatable="false" name="status_bar_ethernet">ethernetstring>
        <string translatable="false" name="status_bar_microphone">microphonestring>
        <string translatable="false" name="status_bar_camera">camerastring>
        <string translatable="false" name="status_bar_airplane">airplanestring>
        <string translatable="false" name="status_bar_sensors_off">sensors_offstring>
        <string translatable="false" name="status_bar_screen_record">screen_recordstring>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73

    frameworks/base/core/res/res/values/symbols.xml中添加xiguatong id,不然引用不到资源

      <java-symbol type="string" name="status_bar_xiguatong" />
      <java-symbol type="string" name="status_bar_battery" />
    
    • 1
    • 2

    systemui部分
    vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

    private final StatusBarIconController mIconController;//状态栏图标控制器
    //自己加的西瓜桶图标
    private final String mXiGuaTong;
    private boolean mXiGuaTongVisible;
    @Inject
    public PhoneStatusBarPolicy(...){
    	...
    	//
    	mXiGuaTong = resources.getString(com.android.internal.R.string.status_bar_xiguatong);
    	mXiGuaTongVisible = true;
    	...
    }
    public void init() {
    	...
    	//xiGuaTong:字符串,图片,按钮描述
    	mIconController.setIcon(mXiGuaTong, R.drawable.stat_sys_xiguatong,null);
    	//设置图片可见不可见:字符串,Boolean值
    	mIconController.setIconVisibility(mXiGuaTong, mXiGuaTongVisible);
    	...
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    以上,就可以在状态栏右侧添加新图标。

    遗留问题

    1、图标是怎么加到状态栏右边的,完整流程?
    2、状态栏左边怎么加图标?
    3、状态栏、下拉状态栏、2次下拉状态栏、锁屏、这几种状态下状态栏图标会有变化,是哪里控制的?

  • 相关阅读:
    生信云实证Vol.12:王者带飞LeDock!开箱即用&一键定位分子库+全流程自动化,3.5小时完成20万分子对接
    《护理教育学》试题
    网络安全与IP安全
    think-cell 数据表无法打开怎么办
    ECCV 2022 | 悉尼大学提出:绝对尺度感知,鲁棒,以及可泛化的自监督单目深度估计网络DynaDepth
    设计模式:模板模式(C#、JAVA、JavaScript、C++、Python、Go、PHP)
    度量BGP监测源数量对AS可见性的影响
    使用C#调用P6 Primavera WebService(自建服务IntegrationAPI)
    篇12:samba服务器的搭建与配置
    阿里P9大神熬夜整合最全PDF:深入实践Mybatis技术原理与实战
  • 原文地址:https://blog.csdn.net/a396604593/article/details/124193812