How to match text color with notification color ba

2019-05-10 02:56发布

问题:

My application use white color font which is okay on my phone that has a black theme. But on other phone the notification bar color and the menus background color is white or a light color. Is there any way (beside giving the user the option to chose the color in the app settings) to know what kind of color or dark/light theme use the phone and match the font color ?

回答1:

When you use Notification and set the text by using built-in means, the following line creates the layout:

RemoteViews contentView = new RemoteViews(context.getPackageName(),
        com.android.internal.R.layout.status_bar_latest_event_content);

The mentioned layout contains the following View which is responsible for viewing notification text:

<TextView android:id="@+id/text"
    android:textAppearance="@style/TextAppearance.StatusBar.EventContent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:paddingLeft="4dp"
    />

So the conclusion is that the needed style is TextAppearance.StatusBar.EventContent, which definition looks like this:

<style name="TextAppearance.StatusBar.EventContent">
    <item name="android:textColor">#ff6b6b6b</item>
</style>

You should note here that this style doesn't actually reference any of the built-in colors, so the safest way is to apply this style instead of some built-in color.



回答2:

I use android:textAppearance="@style/TextAppearance.AppCompat.Notification.Title" work for me