我在自定义布局上放置TextView以获取通知。 TextView的颜色自动变为白色。 这是Android的错误吗?因为在Lollipop之前,通知背景曾经是深色,所以白色文字很有意义。现在在Lollipop上,默认背景是白色,因此白色文本是不可见的。
或者我应该明确地设置文本颜色?放置android:textColor =" @android:color / primary_text_light"使文字变黑,但不保证所有Lollipop设备都有白色通知背景,是吗?
无论系统的背景颜色如何,保证自定义通知上的文字始终可见的正确方法是什么?
在Android Studio上预览
在实际的5.1.1设备上
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, world"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"/>
</LinearLayout>
&#13;
答案 0 :(得分:0)
对于仍在寻找此问题解决方案的所有人,我认为最好的选择是定义TextView
到
TextAppearance.StatusBar.EventContent
在棒棒糖之前和
@android:style/TextAppearance.Material.Notification.Title
for API&gt; = 21。像这样的东西
<强> styles.xml 强>
<style name="NotificationTextColor.Title" parent="TextAppearance.StatusBar.EventContent"></style>
<强> V21 / styles.xml 强>
<style name="NotificationTextColor.Title" parent="@android:style/TextAppearance.Material.Notification.Title"></style>
<强> layout.xml 强>
<TextView
android:id="@+id/notification_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/NotificationTextColor.Title"
tools:text="text"/>