机器人的TextView:设置背景颜色动态不起作用 [英] android TextView: setting the background color dynamically doesn't work

查看:225
本文介绍了机器人的TextView:设置背景颜色动态不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置一个Android的TextView的背景颜色编程方式似乎并没有工作。 我我失去了一些东西!

 的TextView等=新的TextView(活动);
et.setText(350);
et.setBackgroundColor(R.color.white);
 

我也有这个文件(colors.xml)在我RES /值文件夹

 <资源>
        <颜色名称=白>#FFFFFFFF< /彩色>
        <颜色名称=黑>#FF000000< /彩色>
< /资源>
 

: 此外,设置文本的颜色会导致TextView中消失。

  TextView的C1 =新的TextView(活动);
c1.setTextColor(R.color.solid_red);
c1.setText(我的文字);
 

解决方案

使用 et.setBackgroundResource(R.color.white);

Setting the background color programatically of an android TextView doesn't seem to work. I'm I missing something!

TextView et = new TextView(activity);
et.setText("350");
et.setBackgroundColor(R.color.white);

I also have this file (colors.xml) in my res/values folder

<resources>
        <color name="white">#ffffffff</color>
        <color name="black">#ff000000</color>
</resources>

[EDIT]: Also, setting the text color causes the TextView to disappear.

TextView c1 = new TextView(activity);
c1.setTextColor(R.color.solid_red);
c1.setText("My Text");

解决方案

Use et.setBackgroundResource(R.color.white);

这篇关于机器人的TextView:设置背景颜色动态不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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