gpt4 book ai didi

android - 如何将文本颜色与通知颜色栏相匹配?

转载 作者:太空宇宙 更新时间:2023-11-03 13:35:22 25 4
gpt4 key购买 nike

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

最佳答案

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

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

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

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

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

关于android - 如何将文本颜色与通知颜色栏相匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7983153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com