如何使用默认通知样式?

Mel*_*Mel 12 notifications android styles

我和这篇文章有完全相同的问题.我希望我的自定义通知文本样式与默认通知匹配(我只是添加一些额外的视图).不幸的是,我不完全理解接受的答案.我想我应该添加到XML代码但不确定究竟是什么...... 在此输入图像描述

接受的答案是"解决方案是使用内置样式.你需要的样式是TextAppearance.StatusBar.EventContent.只需应用这个样式,它将设置通知的默认文本颜色(不要忘记android:前缀,当然)."

我不能让这个工作!在我的自定义通知下面的行"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"
 />
Run Code Online (Sandbox Code Playgroud)

自定义通知布局和文本颜色

Mel*_*Mel 24

最后弄清楚我做错了什么......(当我只在API 8上开发时,基本上我使用的是API 9中的功能).

首先,使用默认(平台)样式使用...

style ="@ android:style/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"    />
Run Code Online (Sandbox Code Playgroud)

其次要使用StatusBar默认样式使用..

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

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

等等

例如,

    <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"   />
Run Code Online (Sandbox Code Playgroud)

在我的情况下,这导致了一个错误,因为我仍在使用Android 2.2(API 8)进行开发,而这些StatusBar样式用于API 9以上.(我知道我应该更新:))

有用的链接是;

Android.com应用样式和主题,使用平台样式和主题

Android.com R.style参考

StackOverflow.com自定义通知布局和文本颜色

Android.com Android API级别