Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use default notification style?

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

like image 794
Mel Avatar asked Jun 06 '11 09:06

Mel


1 Answers

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

like image 126
Mel Avatar answered Sep 21 '22 07:09

Mel