How to match text color with notification color bar?

↘锁芯ラ 提交于 2019-12-07 16:05:31

问题


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



来源:https://stackoverflow.com/questions/7983153/how-to-match-text-color-with-notification-color-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!