【问题标题】:How to match text color with notification color bar?如何将文本颜色与通知颜色栏匹配?
【发布时间】:2011-12-20 10:54:48
【问题描述】:

我的应用程序使用白色字体,这在我的黑色主题手机上是可以的。 但在其他手机上,通知栏颜色和菜单背景颜色为白色或浅色。有什么方法(除了让用户在应用程序设置中选择颜色之外)知道手机使用哪种颜色或深色/浅色主题并匹配字体颜色?

【问题讨论】:

  • 看看this post。它将帮助您了解可以做什么和不可以做什么。

标签: android colors notifications themes android-notification-bar


【解决方案1】:

当您使用 Notification 并使用内置方式设置文本时,以下行将创建布局:

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

上述布局包含以下负责查看通知文本的视图:

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

所以结论是需要的样式是TextAppearance.StatusBar.EventContent,其定义如下:

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

您应该在此处注意,此样式实际上并未引用任何内置颜色,因此最安全的方法是应用此样式而不是某些内置颜色。

【讨论】:

【解决方案2】:

我使用 android:textAppearance="@style/TextAppearance.AppCompat.Notification.Title" 为我工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-13
    • 2015-12-21
    • 1970-01-01
    相关资源
    最近更新 更多