5.1.1通知TextView,处理白色文本的正确方法? [英] 5.1.1 notification TextView, the correct way to deal with white text?

查看:105
本文介绍了5.1.1通知TextView,处理白色文本的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将TextView放在自定义布局上以进行通知. TextView的颜色自动变为白色. 这是Android的错误吗?因为在Lollipop之前,通知背景以前是深色的,所以白色文本很有意义.现在在Lollipop上,默认背景是白色,因此白色文本是不可见的.

I put a TextView on a custom layout for a notification. The colour of the TextView becomes automatically white. Is this a bug of Android? Because prior to Lollipop, notification background used to be a dark colour, so a white text made sense. Now on Lollipop, the default background is white, so the white text is invisible.

还是我应该明确设置文本颜色?将android:textColor ="@ android:color/primary_text_light"设置为黑色,但不能保证所有Lollipop设备都具有白色通知背景,是吗?

Or am I supposed to set text colour explicitely? Putting android:textColor="@android:color/primary_text_light" made the text black, but it is not guaranteed that all Lollipop devices have white notification background, is it?

无论系统背景颜色如何,确保自定义通知中的文本始终可见的正确方法是什么?

在Android Studio上预览

Preview on Android Studio

在实际的5.1.1设备上

On an actual 5.1.1 device

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

推荐答案

对于仍在寻找该问题解决方案的每个人,我认为最好的选择是将TextView的样式定义为

For everyone still looking for a solution for this question, I think that the best alternative is to define the style of your TextView to

TextAppearance.StatusBar.EventContent

棒棒糖之前,和

@android:style/TextAppearance.Material.Notification.Title

对于API> = 21.像这样

for APIs >=21. Something like this

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

这篇关于5.1.1通知TextView,处理白色文本的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆