Android status bar customization and Modification

Source: Internet
Author: User

Everyone knows the importance of customization in Android development, because through customization, you can create products with different business trips to meet the needs of more consumers,
Mobile phones like HTC have all passed in-depth secondary development. Today I will share my status bar customization.
If you don't talk nonsense, simply:

The background, text color, and Icon display sequence are changed.
2. Key code
A) Position of the Code in the system
The status bar code is located at: Frameworks/base/services/Java/COM/Android/Server/status.
Among them, the statusbarpolicy class is mainly responsible for receiving Action Actions, and some other core operations are all in the statusbarservice class.
B) code example:
I. Receive action
If (action. Equals (intent. action_battery_changed ))
{
Updatebattery (intent );
}
Ii. Update the icon
Private final void updatebattery (intent)
{
Mbatterydata. iconid = intent. getintextra ("icon-small", 0 );
Mbatterydata. iconlevel = intent. getintextra ("level", 0 );
Mservice. updateicon (mbatteryicon, mbatterydata, null );
}
C) resource location:
Status Bar resources are located at: Frameworks/base/CORE/RES. The key layout is base/CORE/RES/layout/status_bar.xml. The source code is as follows: the important part is the red font annotation. You can set the notification font color here.

<COM. android. server. status. statusbarview xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Background = "@ drawable/statusbar_background" <br/> Android: Orientation = "vertical" <br/> Android: focusable = "true" <br/> Android: descendantfocusability = "afterdescendants" <br/> <linearlayout Android: id = "@ + ID/icons" <br/> Android: layout_width = "match_parent" <br/> Android: layout_heig Ht = "match_parent" <br/> Android: Orientation = "horizontal"> </P> <p> <COM. android. server. status. iconmerger <br/> Android: Id = "@ + ID/notificationicons" <br/> Android: layout_width = "0dip" <br/> Android: layout_weight = "1" <br/> Android: layout_height = "match_parent" <br/> Android: layout_alignparentright = "true" <br/> Android: paddingleft = "6dip" <br/> Android: gravity = "center_vertical" <br/> Android: Orientation = "H Orizontal "/> </P> <p> <linearlayout <br/> Android: Id =" @ + ID/statusicons "<br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "match_parent" <br/> Android: layout_alignparentleft = "true" <br/> Android: paddingright = "6dip" <br/> Android: gravity = "center_vertical" <br/> Android: orientation = "horizontal"/> <br/> </linearlayout> </P> <p> <linearlayout Android: id = "@ + ID/ticker" <br/> Android: Lay Out_width = "match_parent" <br/> Android: layout_height = "match_parent" <br/> Android: paddingleft = "6dip" <br/> Android: animationcache = "false" <br/> Android: Orientation = "horizontal"> <br/> <imageswitcher Android: Id = "@ + ID/tickericon" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "match_parent" <br/> Android: layout_marginright = "8dip" <br/> <COM. android. server. status. anima Tedimageview <br/> Android: layout_width = "25dip" <br/> Android: layout_height = "25dip" <br/> <COM. android. server. status. animatedimageview <br/> Android: layout_width = "25dip" <br/> Android: layout_height = "25dip" <br/> </imageswitcher> <br/> <COM. android. server. status. tickerview Android: Id = "@ + ID/tickertext" <br/> Android: layout_width = "0dip" <br/> Android: layout_weight = "1" <br/> Android: Layout_height = "wrap_content" <br/> Android: paddingtop = "2dip" <br/> Android: paddingright = "10dip"> <br/> <textview <br/> Android: layout_width = "match_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: singleline = "true" <br/> Android: textcolor = "# ff000000"/> <br/> <textview <br/> Android: layout_width = "match_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: singleline = "true "<Br/> Android: textcolor =" # ff000000 "/> <br/> </COM. android. server. status. tickerview> <br/> </linearlayout> <br/> <COM. android. server. status. dateview Android: Id = "@ + ID/date" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "match_parent" <br/> Android: singleline = "true" <br/> Android: textsize = "16sp" <br/> Android: textstyle = "bold" <br/> Android: gravity = "center_vertical | left" <br /> Android: paddingleft = "6px" <br/> Android: paddingright = "6px" <br/> Android: textcolor = "? Android: ATTR/textcolorprimaryinverse "<br/> Android: Background =" @ drawable/statusbar_background "<br/> </COM. android. server. status. statusbarview> 

3. Simple Modification
Changes to the status bar mainly include the background color, icon, font color, and Icon sequence of the status bar.
A) background color:
The background color is determined by frameworks/base/CORE/RES/drawable-mdpi/statusbar_background.9.png. The original color is gray and we change it to black.
B) icon:
The icon is determined by different display items and is not changed for the time being.
C) font color:
It is controlled by the code in the frameworks/base/services/Java/COM/Android/Server/status/statusbaricon class. The original code is T. settextcolor (0xff000000), that is, black, we change it to White: T. settextcolor (0 xffffffff ).
D) icon sequence:
Controlled by resource files in frameworks/base/CORE/RES/values/array, the original code is as follows:

<String-array name = "status_bar_icon_order"> <br/> <item> <xliff: G id = "ID"> clock </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> secure </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> alarm_clock </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> battery </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> phone_signal </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> phone_evdo_signal </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> data_connection </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> CDMA _eri </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> tty </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> volume </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> mute </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> speakerphone </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> WiFi </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> tty </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> Bluetooth </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> GPS </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> sync_active </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> sync_failing </xliff: g> </item> <br/> <item> <xliff: G id = "ID"> IME </xliff: g> </item> <br/> </string-array> 

We will change the location of the battery and clock.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.