在状态栏右边添加一个自定义图标,根据广播更新图标。
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>
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" />
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、状态栏、下拉状态栏、2次下拉状态栏、锁屏、这几种状态下状态栏图标会有变化,是哪里控制的?