Home>

Everyone knows the importance of customization in android development,Because through customization,Can you make a differentiated product,To meet the needs of more consumers,

Mobile phones like htc have undergone deep secondary development,Today I will also share my status bar customization.

Stop talking nonsense,Directly above:

Mainly changed the background,Text color and the order in which icons are displayed.

2. The key code part

a) The location of the code in the system

The relevant code for the status bar is located at:frameworks/base/services/java/com/android/server/status.

The statusbarpolicy class is mainly responsible for receiving action actions, and some other core operations are located in the statusbarservice class.

b) Code example:

i. Receive 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 related resources of status bar are located in:frameworks/base/core/res/res, the key layout is:base/core/res/res/layout/status_bar.xml,

The 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="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. Simple modification

The modifications to the status bar mainly include the background color, icon, font color, and icon order of the status bar.

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 modified it to black.

b) icon:

icon according to different display items,Determined by different resources,No changes for now.

c) font color:

Controlled by code in the frameworks/base/services/java/com/android/server/status/statusbaricon class,The original code was:t.settextcolor (0xff000000), which is black, we changed it to white:t.settextcolor (0xffffffff).

d) Icon sequence:

Controlled by resource files in frameworks/base/core/res/res/values ​​/array,The original code is as follows:

<string-array name="status_bar_icon_order">
    <item><xliff:g>clock</xliff:g></item>
    <item><xliff:g>secure</xliff:g></item>
    <item><xliff:g>alarm_clock</xliff:g></item>
    <item><xliff:g>battery</xliff:g></item>
    <item><xliff:g>phone_signal</xliff:g></item>
    <item><xliff:g>phone_evdo_signal</xliff:g></item>
    <item><xliff:g>data_connection</xliff:g></item>
    <item><xliff:g>cdma_eri</xliff:g></item>
    <item><xliff:g>tty</xliff:g></item>
    <item><xliff:g>volume</xliff:g></item>
    <item><xliff:g>mute</xliff:g></item>
    <item><xliff:g>speakerphone</xliff:g></item>
    <item><xliff:g>wifi</xliff:g></item>
    <item><xliff:g>tty</xliff:g></item>
    <item><xliff:g>bluetooth</xliff:g></item>
    <item><xliff:g>gps</xliff:g></item>
    <item><xliff:g>sync_active</xliff:g></item>
    <item><xliff:g>sync_failing</xliff:g></item>
    <item><xliff:g>ime</xliff:g></item>
</string-array>

We changed the position of battery and clock.

  • Previous Android code to write controls instead of XML simple examples
  • Next Simple and practical example code for Ajax