账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    背景颜色影响 TextView 内容默名消失问题?
    53
    0

    在自定义的 BroadcastReceiver 中,更新一个TextView 的背影颜色
    tvHead.setBackgroundColor(getResources().getColor(R.color.yellow));
    然后弹一个 dialog 出来,点关闭后,另一处的一个 TextView 内容就变空了,我加addTextChangedListener 来监听内容的变化,发现 TextView 变空时 没监听到

    当我把上面设置背景的代码注释掉后 另一个TextView 就不会变空了。

    这两个控件完全没任何关系,感觉莫名其妙,完全不知道什么原因,各位大佬请赐教下

    就只是在 BroadcastReceiver 中注释 setBackgroundColor 这一句就正常了,实在不知道啥原因

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 请叫我儿媳。 普通会员 1楼

      背景颜色确实可能影响TextView中的内容默名消失问题。这是因为文本默认的颜色和背景颜色可能不会完全匹配,特别是在某些情况下,如背景颜色为白色,文本颜色为黑色,这可能导致文本和背景颜色之间的对比度不足,从而导致内容默名消失。

      要解决这个问题,您可以尝试以下几种方法:

      1. 设置文本颜色和背景颜色:您可以使用android:textColorandroid:textColorStateList属性来设置文本颜色和背景颜色。例如:

      xml <TextView android:textColor="@android:color/black" android:textColorStateList="@android:color/white" ... />

      1. 使用自定义字体:您可以使用自定义字体来设置文本颜色。例如,您可以创建一个自定义字体,并在TextView中使用android:fontFamily属性来设置字体。例如:

      xml <TextView android:fontFamily="@font/myfont" android:textColor="@android:color/black" android:textColorStateList="@android:color/white" ... />

      1. 使用背景颜色更替:您可以使用android:background属性来设置背景颜色,并使用android:backgroundTintList属性来设置背景颜色的变体。例如:

      xml <TextView android:background="@android:color/white" android:backgroundTintList="@android:color/white" android:textColor="@android:color/black" android:textColorStateList="@android:color/white" ... />

      1. 使用android:ellipsize属性:您可以使用android:ellipsize属性来控制文本的大小。例如,您可以设置android:ellipsize="end"来使文本在页面末尾结束,而不是在中间消失。例如:

      xml <TextView android:ellipsize="end" android:textColor="@android:color/black" android:textColorStateList="@android:color/white" ... />

      以上都是一些可能的解决方案,您可以根据自己的需求和喜好选择合适的解决方案。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部