systemUI整体布局为super_status_bar.xml:
1、status_bar.xml:状态栏+通知浮动ticker(状态栏的透明背景一般在这一块去修改),状态栏上的图标可以在framework中定义,如下。
-----路径:\frameworks\base\core\res\res\values\config.xml
<string-array name="config_statusBarIcons"> <item><xliff:g id="id">ime</xliff:g></item> <item><xliff:g id="id">sync_failing</xliff:g></item> <item><xliff:g id="id">sync_active</xliff:g></item> <item><xliff:g id="id">gps</xliff:g></item> <item><xliff:g id="id">bluetooth</xliff:g></item> <item><xliff:g id="id">nfc</xliff:g></item> <item><xliff:g id="id">tty</xliff:g></item> <item><xliff:g id="id">speakerphone</xliff:g></item> <item><xliff:g id="id">mute</xliff:g></item> <item><xliff:g id="id">volume</xliff:g></item> <item><xliff:g id="id">wifi</xliff:g></item> <item><xliff:g id="id">cdma_eri</xliff:g></item> <item><xliff:g id="id">phone_signal_second_sub</xliff:g></item> <item><xliff:g id="id">data_connection</xliff:g></item> <item><xliff:g id="id">phone_evdo_signal</xliff:g></item> <item><xliff:g id="id">phone_signal</xliff:g></item> <item><xliff:g id="id">battery</xliff:g></item> <item><xliff:g id="id">alarm_clock</xliff:g></item> <item><xliff:g id="id">secure</xliff:g></item> <item><xliff:g id="id">clock</xliff:g></item> </string-array>
其使用的地方也很广,可以在systemUI本身里面com.android.systemUI.statusbar.phone.PhoneStatusBarPolicy.java。也可以在其他应用,譬如拨号EmergencyDialer中的
com.android.phone.NotificationMgr.java类中,其在显示拨打电话的后台外放音模式下,在状态栏右边会出现一个小图标。
A、systemUI中部分实现如下:(systemUI中的图标多半通过广播来判断图标消失与否)
private StatusBarManager mService = (StatusBarManager)mContext.getSystemService(Context.STATUS_BAR_SERVICE); mService.setIcon("headset_statusBarIcons",R.drawable.stat_sys_headset,null); mService.setIconVisibility("headset_statusBarIcons",false); public void updateHeadSetImage(int value) { if (value == 1) { mService.setIconVisibility("headset_statusBarIcons",true); }else{ mService.setIconVisibility("headset_statusBarIcons",false); } } private final void updateHeadset(Intent intent) { if (intent.hasExtra("state")) { int value = intent.getIntExtra("state",0); Settings.System.putInt(mContext.getContentResolver(),"headset_statusbar",value); updateHeadSetImage(value); } } private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context,Intent intent) { if (action.equals("android.intent.action.HEADSET_PLUG")) { updateHeadset(intent); } } }; private final Handler mHandler = new Handler(); IntentFilter filter = new IntentFilter(); filter.addAction("android.intent.action.HEADSET_PLUG"); mContext.registerReceiver(mIntentReceiver,filter,null,mHandler);
B、 EmergencyDialer中部分实现如下:
private StatusBarManager mService = (StatusBarManager)mContext.getSystemService(Context.STATUS_BAR_SERVICE); mService.setIconVisibility("上述item中定义的名字",true/false); mService.setIcon("上述item中定义的名字",R.drawable.需要显示的图片,mContext.getString
(R.string.accessibility_speakerphone_enabled)); mService.removeIcon(“上述item中定义的名字");
也可以在status_bar.xml中直接定义,像电池,信号,时钟等。因此当我们想定制简单的状态栏图标可以在framework与xml文件这两种方法里,而当想定制比较复杂的状态栏图标
类似未接电话图标加个数则可以在xml中自定义。
2、status_bar_expanded.xml:托盘下拉
这一块可以定制很多样式,像小米的android.support.v4.view.ViewPager