[Android] 通知トラッキングビューの背景を変更する

| トラックバック(0) |

ステータスバーを引き下げた時に表示される(通知トラッキング)ビューの背景を変更してみました。

※標準の背景に似せて(おもむきのある版画風)グレースケール透過にしていますが、背景画像はフルカラー使用可能です

 

 

解説

ステータスバーを引き下げた時に表示される(通知トラッキング)ビューの背景は、デフォルトでは、色リソースとして定義されています。 

  • android-4.0.3_r1\frameworks\base\packages\SystemUI\res\values\colors.xml
<resources>
    <drawable name="notification_tracking_bg">#d8000000</drawable>
</resources>

したがって、上記の「notification_tracking_bg」の行をコメントアウトし、

「drawable(-hdpi)」フォルダ下に「notification_tracking_bg.png」というファイル名の画像を置くことで、背景を差し替えできます。

 

外部ストレージに配置した画像を読み込んで配置する

カスタマイズしやすいように外部ストレージに配置した画像を読み込んで配置するには、以下のようなコードで実現できます。 

  • android-4.0.3_r1\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\PhoneStatusBar.java
import android.view.animation.AnimationUtils;
// 追加 ->
import android.widget.FrameLayout;
// 追加 <-
import android.widget.ImageView;
public class PhoneStatusBar extends StatusBar {
    protected View makeStatusBarView() {
// ・・・省略・・・
        TickerView tickerView = (TickerView)sb.findViewById(R.id.tickerText);
        tickerView.mTicker = mTicker;
        mTrackingView = (TrackingView)View.inflate(context, R.layout.status_bar_tracking, null);
// 追加 ->
{
    String IMAGE_FILENAME = "notification_tracking_bg.png";
    FrameLayout f = (FrameLayout) mTrackingView.findViewById(R.id.notification_tracking_bg);
    StringBuilder builder = new StringBuilder();
    builder.append(Environment.getExternalStorageDirectory().toString());
    builder.append(File.separator);
    builder.append(IMAGE_FILENAME);
    String filePath = builder.toString();
    Drawable drawable = Drawable.createFromPath(filePath);
    if (drawable != null) {
        f.setBackgroundDrawable(drawable);
    }
}
// 追加 <-
        mTrackingView.mService = this;
// ・・・省略・・・

※読み込むフォルダ位置(ここではSDカード直下)は、適宜変更してください

 

  • android-4.0.3_r1\frameworks\base\packages\SystemUI\res\layout\status_bar_tracking.xml
<com.android.systemui.statusbar.phone.TrackingView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:visibility="gone"
    android:focusable="true"
    android:descendantFocusability="afterDescendants"
    android:paddingBottom="0px"
    android:paddingLeft="0px"
    android:paddingRight="0px"
    >
<!-- 以下のandroid:idの1行のみを追加 -->
    <FrameLayout
android:id="@+id/notification_tracking_bg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/notification_tracking_bg"
        >
        <com.android.systemui.statusbar.phone.CarrierLabel
            android:textAppearance="@style/TextAppearance.StatusBar.Clock"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_gravity="bottom"
            android:gravity="center"
            android:paddingBottom="20dp"
            />
    </FrameLayout>

※変更した部分が強調されるようにインデントをずらしています

 

あわせて読みたい

  • sola : [カスタムROM開発] Galaxy Nexus 向けのカスタムROM を更新(2012/02/19)

トラックバック(0)

トラックバックURL: http://mt.adakoda.com/mt-tb.cgi/568

2016年8月

  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31