2011-06-06 5 views
12

私はthis postとまったく同じ問題があります。私は私のカスタム通知のテキストスタイルをデフォルトの通知に一致させたい(私はちょっと追加のビューを追加するつもりだ)。残念ながら私は受け入れられた答えを完全に理解していません。私は受け入れ答えは ソリューションは、組み込みのスタイルを使用することである」と言う。あなたが必要とするスタイルがTextAppearance.StatusBarである私はXMLコードに追加するためのものだと思ったがわからない、まさに... enter image description hereデフォルト通知スタイルの使い方は?

。 EventContent。このスタイルを適用するだけで、通知用のデフォルトのテキスト色が設定されます(もちろんandroid:prefixということを忘れないでください)。 "

これはうまくいきません! "android:textAppearance =" android:attr/textAppearanceLarge "という行の下の私のカスタム通知で、テキストが拡大されますが、目的の効果は得られません。

ここに私のカスタムXMLコードです...

<ImageView 
    android:id="@+id/notImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="10dp" 
    android:layout_alignParentTop="true"/> 

<TextView 
    android:id="@+id/notContentTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf ="@id/notImage" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:id="@+id/notContentText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below ="@id/notContentTitle" 
/> 

Custom notification layouts and text colors

答えて

24

最後に、私は基本的に(...私が間違って何をしていたかを考え出しました私はAPI 8で開発しているときにAPI 9の機能を使用していました)。まず

、デフォルト(プラットフォーム)スタイルの使用を使用するには...

スタイル= "@android:スタイル/ TextAppearance.Small" 例えば

...

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" android:padding="3dp"> 

<ImageView 
    android:id="@+id/notImage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="10dp" 
    android:layout_alignParentTop="true"/> 

<TextView 
    android:id="@+id/notContentTitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf ="@id/notImage" 
    android:textStyle="bold" 
    style = "@android:style/TextAppearance.Medium"/> 

<TextView 
    android:id="@+id/notContentText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below ="@id/notImage" 
    style = "@android:style/TextAppearance.Small" /> 
第二

ステータスバーのデフォルトのスタイルの使用を使用する..

スタイル= "@android:スタイル/ TextAppearance.StatusBar.EventContent" または

スタイル= "@android:スタイル/ TextAppearance.StatusBar.EventContent.Title"、

などなど

これらのステータスバーのスタイルは、以降のAPI 9のためのものである一方で、私はまだアンドロイド2.2(API 8)を開発していますので、

は例えば、私の場合は

<TextView 
    android:id="@+id/notContentText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below ="@id/notImage" 
    style = "@android:style/TextAppearance.StatusBar.EventContent" /> 

が、これはエラーの原因となりました。(私は更新する必要があります:))

便利なリンクです。

Android.com Applying Styles and Themes, Using Platform Styles and Themes

Android.com R.style reference

StackOverflow.com Custom notification layouts and text colours

Android.com Android API levels

+0

だけので、我々は正しい、前API9にデフォルトの通知スタイルを使用する方法はありません...明らかですか? –

+0

残念ながら、はい。私の答え(http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/4935191#4935191)で説明したように、APIレベル8以前では、ハードコードされた値しかありませんこれはアクセスできません。 – Malcolm

+1

答え(http://stackoverflow.com/a/7320604/435605)は、2.2の色を見つける方法を提供します。 –

関連する問題