Android狀態列定製和修改

來源:互聯網
上載者:User

大家都知道定製在android開發中的重要性,因為通過定製,你才能製造出差異化的產品,才能滿足更多消費者的需求,
像HTC生產的手機都通過了深層次的二次開發,今天我也來分享一下我的狀態欄定製。
廢話不說了,直接:

主要更換了背景,文字顏色以及icon的顯示順序.
2.    關鍵代碼部分
a)    代碼在系統中的位置
status bar 的相關代碼位於:frameworks/base/services/java/com/android/server/status。
其中StatusBarPolicy類主要負責接收action動作,其他一些核心操作全部位於StatusBarService類裡面
b)    代碼執行個體:
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 的相關資源位於:frameworks/base/core/res/res,關鍵布局為:base/core/res/res/layout/status_bar.xml ,源碼如下:重要的是紅色字型標註部分,這裡可以設定notification字型顏色。

<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 /> ><br /> <LinearLayout android:id="@+id/icons"<br /> android:layout_width="match_parent"<br /> android:layout_height="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="horizontal"/> </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:layout_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 /> ><br /> <com.android.server.status.AnimatedImageView<br /> android:layout_width="25dip"<br /> android:layout_height="25dip"<br /> /><br /> <com.android.server.status.AnimatedImageView<br /> android:layout_width="25dip"<br /> android:layout_height="25dip"<br /> /><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 /> /><br /></com.android.server.status.StatusBarView> 

3.    簡單修改
對status bar 的修改主要包括status bar的背景顏色、icon、字型顏色、icon順序等。
a)    背景顏色:
背景顏色由frameworks/base/core/res/res/drawable-mdpi/statusbar_background.9.png決定,原始顏色是灰色,我們修改為黑色。
b)    Icon:
Icon根據不同顯示項目,由不同資源決定,暫時不更改。
c)    字型顏色:
由frameworks/base/services/java/com/android/server/status/ StatusBarIcon類中的代碼控制,原始代碼為:t.setTextColor(0xff000000),即黑色,我們將其更改為白色:t.setTextColor(0xffffffff)。
d)    icon順序:
由frameworks/base/core/res/res/values/array裡面的資源檔控制,原始代碼如下:

<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> 

我們將battery與clock的位置更換。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.