Android implementation of the status bar customization and modification methods _android

Source: Internet
Author: User

This article describes the implementation of the Android status bar customization and modification methods. Share to everyone for your reference. Specifically as follows:

We all know the importance of customization in Android development, because by customizing, you can create differentiated products to meet the needs of more consumers,

Like HTC production of mobile phones have been through a deep two of development, today I also share my status bar customization.

Nonsense not to say, directly above the figure:

The main change of the background, text color and icon display order.

2. Key Code section

A) The location of the code in the system

The relevant code for status bar is located at: Frameworks/base/services/java/com/android/server/status.
Where the Statusbarpolicy class is mainly responsible for receiving action actions, some other core operations are all located in the Statusbarservice class

b) Code example:

I. Receiving ACTION

if (Action.equals (intent.action_battery_changed)) 
{
  updatebattery (Intent);
}

Ii. Update 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) Resource location:

The relevant resources for Status Bar are located at: frameworks/base/core/res/res, the key layout is: Base/core/res/res/layout/status_bar.xml,

Source code is as follows: Here you can set the notification font color.

<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= "MATC" H_parent "android:layout_height=" match_parent "android:orientation=" Horizontal "> <com.android.server.sta Tus.
      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_al" Ignparentleft= "true" Android:paddingright= "6dip" android:gravity= "center_vertical" android:orientation= "Horizontal"/> </LinearLayou t> <linearlayout android:id= "@+id/ticker" android:layout_width= "match_parent" match _parent "android:paddingleft=" 6dip "android:animationcache=" false "android:orientation=" Horizontal "> & Lt;imageswitcher android:id= "@+id/tickericon" android:layout_width= "wrap_content" match
        _parent "android:layout_marginright=" 8dip "> <com.android.server.status.animatedimageview Android:layout_width= "25dip" android:layout_height= "25dip"/> <com.android.server.status.anima Tedimageview android:layout_width= "25dip" android:layout_height= "25dip"/> </imageswitch er> <com.android.server.status.tickerview android:id= "@+id/tickertext" android:layout_width= "0dip" a ndroid:layout_weight= "1"
      android:layout_height= "Wrap_content" android:paddingtop= "2dip" android:paddingright= "10dip" > & Lt TextView android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:singleli
        Ne= "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:single Line= "true" android:textsize= "16sp" android:textstyle= "bold" android:gravity= "Center_vertical|left" Androi d:paddingleft= "6px" android:paddingright= "6px" android:textcolor= "Android:attr/textcolorprimaryinverse" Andro id:background= "@drawable/statusbAr_background "/> </com.android.server.status.StatusBarView>

 

3. Simple modification

The changes to the status bar mainly include the background color of the status bar, icon, font Color, icon order, and so on.

A) Background color:

The background color is determined by frameworks/base/core/res/res/drawable-mdpi/statusbar_background.9.png, the original color is gray, we modify it to black.

b) Icon:

Icon according to different display items, determined by different resources, temporarily do not change.

c) Font Color:

Controlled by 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 (0xFFFFFFFF).

d) Icon Order:

Controlled by the resource file inside the Frameworks/base/core/res/res/values/array, the original code is as follows:

<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" & Gt;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" >speak Erphone</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>

We will replace the battery with the clock position.

I hope this article will help you with your Android program.

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.