Android實(shí)現(xiàn)的狀態(tài)欄定制和修改方法
本文實(shí)例講述了Android實(shí)現(xiàn)的狀態(tài)欄定制和修改方法。分享給大家供大家參考。具體如下:
大家都知道定制在android開(kāi)發(fā)中的重要性,因?yàn)橥ㄟ^(guò)定制,你才能制造出差異化的產(chǎn)品,才能滿(mǎn)足更多消費(fèi)者的需求,
像HTC生產(chǎn)的手機(jī)都通過(guò)了深層次的二次開(kāi)發(fā),今天我也來(lái)分享一下我的狀態(tài)欄定制。
廢話(huà)不說(shuō)了,直接上圖:
主要更換了背景,文字顏色以及icon的顯示順序.
2. 關(guān)鍵代碼部分
a) 代碼在系統(tǒng)中的位置
status bar 的相關(guān)代碼位于:frameworks/base/services/java/com/android/server/status。
其中StatusBarPolicy類(lèi)主要負(fù)責(zé)接收action動(dòng)作,其他一些核心操作全部位于StatusBarService類(lèi)里面
b) 代碼實(shí)例:
i. 接收action
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { updateBattery(intent); }
ii. 更新icon
private final void updateBattery(Intent intent) { mBatteryData.iconId = intent.getIntExtra("icon-small", 0); mBatteryData.iconLevel = intent.getIntExtra("level", 0); mService.updateIcon(mBatteryIcon, mBatteryData, null); }
c) 資源位置:
Status bar 的相關(guān)資源位于:frameworks/base/core/res/res,關(guān)鍵布局為:base/core/res/res/layout/status_bar.xml ,
源碼如下:這里可以設(shè)置notification字體顏色。
<com.android.server.status.StatusBarView xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/statusbar_background" android:orientation="vertical" android:focusable="true" android:descendantFocusability="afterDescendants" > <LinearLayout android:id="@+id/icons" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <com.android.server.status.IconMerger android:id="@+id/notificationIcons" android:layout_width="0dip" android:layout_weight="1" android:layout_height="match_parent" android:layout_alignParentRight="true" android:paddingLeft="6dip" android:gravity="center_vertical" android:orientation="horizontal"/> <LinearLayout android:id="@+id/statusIcons" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:paddingRight="6dip" android:gravity="center_vertical" android:orientation="horizontal"/> </LinearLayout> <LinearLayout android:id="@+id/ticker" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="6dip" android:animationCache="false" android:orientation="horizontal" > <ImageSwitcher android:id="@+id/tickerIcon" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginRight="8dip" > <com.android.server.status.AnimatedImageView android:layout_width="25dip" android:layout_height="25dip" /> <com.android.server.status.AnimatedImageView android:layout_width="25dip" android:layout_height="25dip" /> </ImageSwitcher> <com.android.server.status.TickerView android:id="@+id/tickerText" android:layout_width="0dip" android:layout_weight="1" android:layout_height="wrap_content" android:paddingTop="2dip" android:paddingRight="10dip"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="#ff000000" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textColor="#ff000000" /> </com.android.server.status.TickerView> </LinearLayout> <com.android.server.status.DateView android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="match_parent" android:singleLine="true" android:textSize="16sp" android:textStyle="bold" android:gravity="center_vertical|left" android:paddingLeft="6px" android:paddingRight="6px" android:textColor="?android:attr/textColorPrimaryInverse" android:background="@drawable/statusbar_background" /> </com.android.server.status.StatusBarView>
3. 簡(jiǎn)單修改
對(duì)status bar 的修改主要包括status bar的背景顏色、icon、字體顏色、icon順序等。
a) 背景顏色:
背景顏色由frameworks/base/core/res/res/drawable-mdpi/statusbar_background.9.png決定,原始顏色是灰色,我們修改為黑色。
b) Icon:
Icon根據(jù)不同顯示項(xiàng),由不同資源決定,暫時(shí)不更改。
c) 字體顏色:
由frameworks/base/services/java/com/android/server/status/ StatusBarIcon類(lèi)中的代碼控制,原始代碼為:t.setTextColor(0xff000000),即黑色,我們將其更改為白色:t.setTextColor(0xffffffff)。
d) icon順序:
由frameworks/base/core/res/res/values/array里面的資源文件控制,原始代碼如下:
<string-array name="status_bar_icon_order"> <item><xliff:g id="id">clock</xliff:g></item> <item><xliff:g id="id">secure</xliff:g></item> <item><xliff:g id="id">alarm_clock</xliff:g></item> <item><xliff:g id="id">battery</xliff:g></item> <item><xliff:g id="id">phone_signal</xliff:g></item> <item><xliff:g id="id">phone_evdo_signal</xliff:g></item> <item><xliff:g id="id">data_connection</xliff:g></item> <item><xliff:g id="id">cdma_eri</xliff:g></item> <item><xliff:g id="id">tty</xliff:g></item> <item><xliff:g id="id">volume</xliff:g></item> <item><xliff:g id="id">mute</xliff:g></item> <item><xliff:g id="id">speakerphone</xliff:g></item> <item><xliff:g id="id">wifi</xliff:g></item> <item><xliff:g id="id">tty</xliff:g></item> <item><xliff:g id="id">bluetooth</xliff:g></item> <item><xliff:g id="id">gps</xliff:g></item> <item><xliff:g id="id">sync_active</xliff:g></item> <item><xliff:g id="id">sync_failing</xliff:g></item> <item><xliff:g id="id">ime</xliff:g></item> </string-array>
我們將battery與clock的位置更換。
希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。
- Android ListView的Item點(diǎn)擊效果的定制
- Android快速開(kāi)發(fā)之定制BaseTemplate
- Android實(shí)現(xiàn)定制返回按鈕動(dòng)畫(huà)效果的方法
- Android定制自己的EditText輕松改變底線(xiàn)顏色
- Android 組件樣式定制方法詳解
- Android實(shí)現(xiàn)定制桌面的方法
- android源碼探索之定制android關(guān)機(jī)界面的方法
- Android 如何定制vibrator的各種震動(dòng)模式M 具體方法
- Android定制RadioButton樣式三種實(shí)現(xiàn)方法
- 詳解android系統(tǒng)的定制
相關(guān)文章
Android優(yōu)化之啟動(dòng)頁(yè)去黑屏實(shí)現(xiàn)秒啟動(dòng)
本文的內(nèi)容主要是講Android啟動(dòng)頁(yè)優(yōu)化,去黑屏實(shí)現(xiàn)秒啟動(dòng)的功能,有需要的小伙伴們可以參考學(xué)習(xí)。2016-08-08ffmpeg實(shí)現(xiàn)去水印以及切分視頻demo
這篇文章主要為大家介紹了ffmpeg實(shí)現(xiàn)去水印以及切分視頻demo,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-1113問(wèn)13答全面學(xué)習(xí)Android View繪制
這篇文章主要為大家詳細(xì)介紹了Android View繪制,13問(wèn)13答幫助大家全面學(xué)習(xí)Android View繪制,感興趣的小伙伴們可以參考一下2016-03-03Android開(kāi)發(fā)工程中集成mob短信驗(yàn)證碼功能的方法
這篇文章主要介紹了Android開(kāi)發(fā)工程中集成mob短信驗(yàn)證碼功能的方法,感興趣的小伙伴們可以參考一下2016-05-05解析android創(chuàng)建快捷方式會(huì)啟動(dòng)兩個(gè)應(yīng)用的問(wèn)題
本篇文章是對(duì)關(guān)于android創(chuàng)建快捷方式會(huì)啟動(dòng)兩個(gè)應(yīng)用的問(wèn)題進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06Android 接收微信、QQ其他應(yīng)用打開(kāi)第三方分享功能
這篇文章主要介紹了Android 接收微信、QQ其他應(yīng)用打開(kāi),第三方分享 ,思路很簡(jiǎn)單通過(guò)在A(yíng)ndroidManifest.xml注冊(cè)ACTION事件,在用于接收分享的Activity里面加接收代碼,感興趣的朋友可以一起學(xué)習(xí)下2022-11-11Android Navigation TabBar控件實(shí)現(xiàn)多彩標(biāo)簽欄
這篇文章主要為大家詳細(xì)介紹了Android Navigation TabBar控件實(shí)現(xiàn)多彩標(biāo)簽欄的相關(guān)代碼,感興趣的小伙伴們可以參考一下2016-05-05