12

I have the exact same problem as this post. I want my custom notifications text style to match the default notifications (Im just going to add a few extra views). Unfortunately I don't fully understand the accepted answer. I think I am meant to add to the XML code but not sure exactly what... enter image description here

The accepted answer says" The solution is to use built-in styles. The style you need is TextAppearance.StatusBar.EventContent. Just apply this style and it will set the default text color for notifications (don't forget android: prefix, of course). "

I cant get this to work! In my custom notification below the line "android:textAppearance="?android:attr/textAppearanceLarge" works (as it enlargens the text) but does not give the desired effect.

Here is my custom XML code...

<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

Community
  • 1
  • 1
Mel
  • 6,214
  • 10
  • 54
  • 71

1 Answers1

24

Finally figured out what I was doing wrong... (basically I was using features from API 9 when I am only developing on API 8).

Firstly, to use a default (platform) style use...

style = "@android:style/TextAppearance.Small"

For example...

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

Secondly to use the StatusBar default style use..

style = "@android:style/TextAppearance.StatusBar.EventContent" or

style = "@android:style/TextAppearance.StatusBar.EventContent.Title",

etc, etc.

For example,

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

In my case this caused an error because I am still developing with Android 2.2 (API 8) whilst these StatusBar styles are for API 9 onwards. (I know I should update :))

Useful links are;

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

Community
  • 1
  • 1
Mel
  • 6,214
  • 10
  • 54
  • 71
  • Just so we're clear...there is no way to use default notification styles prior to API9, correct? – Dustin Wyatt Jul 01 '11 at 18:25
  • Unfortunately, yes. As I have explained in my answer (http://stackoverflow.com/questions/4867338/custom-notification-layouts-and-text-colors/4935191#4935191), in API Level 8 and earlier there's only a hard-coded value, which can't be accessed. – Malcolm Jul 18 '11 at 18:57
  • 1
    The answer (http://stackoverflow.com/a/7320604/435605) does provide a way to find the color for 2.2- – AlikElzin-kilaka Dec 06 '11 at 19:36