(转)TextView 设置背景和文本颜色的问题
2014-07-15 22:42
337 查看
在做一个项目,突然遇到如下问题
比如:
在color.xml中定义了几个颜色
<color name="white">#FFFFFF</color>
<color name="orange">#DF8326</color>
复制代码
又给TextView 设置了字体颜色和背景色
<TextView
android:id="@+id/hello"
android:textColor="@color/white"
android:background="@color/orange"
android:text="Hello World"
/>
复制代码
运行之后,显示是正常的,背景为橙色,文字为白色。
但是我动态操作了一下控件,就是把这个TextView 的字体颜色和背景颜色对调一下。
问题出来了,颜色变了,变成了灰色背景,黑色文字。
view_hello.setBackgroundColor(R.color.white);
view_hello.setTextColor(R.color.orange);
复制代码
我尝试了各种颜色格式,这些只是Android支持的: #RGB, #ARGB, #RRGGBB , #AARRGGBB 。
但结果还是一样,开始显示是正常的。经过上面代码操作一下后就变成灰色背景,黑色文字。
为什么会出现这种情况?是什么原因造成的?怎么解决这个问题?
摘自http://www.eoeandroid.com/thread-26787-1-1.html
比如:
在color.xml中定义了几个颜色
<color name="white">#FFFFFF</color>
<color name="orange">#DF8326</color>
复制代码
又给TextView 设置了字体颜色和背景色
<TextView
android:id="@+id/hello"
android:textColor="@color/white"
android:background="@color/orange"
android:text="Hello World"
/>
复制代码
运行之后,显示是正常的,背景为橙色,文字为白色。
但是我动态操作了一下控件,就是把这个TextView 的字体颜色和背景颜色对调一下。
问题出来了,颜色变了,变成了灰色背景,黑色文字。
view_hello.setBackgroundColor(R.color.white);
view_hello.setTextColor(R.color.orange);
复制代码
我尝试了各种颜色格式,这些只是Android支持的: #RGB, #ARGB, #RRGGBB , #AARRGGBB 。
但结果还是一样,开始显示是正常的。经过上面代码操作一下后就变成灰色背景,黑色文字。
为什么会出现这种情况?是什么原因造成的?怎么解决这个问题?
摘自http://www.eoeandroid.com/thread-26787-1-1.html
相关文章推荐
- 富文本的使用之二 设置TextView不同字段的颜色和背景颜色
- Textview动态设置颜色问题
- android:TextView中的文本链接之--设置超链接、颜色、字体等属性
- android--设置TextView部分文字的颜色和背景(高亮显示)
- Android—TextView 背景颜色与背景图片设置
- 最新历史版本 :android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- textView 的设置文本中某一文字的字体颜色以及图文混排
- android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法
- android TextView 设置部分文字背景色和文字颜色
- android--设置TextView部分文字的颜色和背景(高亮显示)
- 最新历史版本 :android--设置TextView部分文字的颜色和背景(高亮显示)
- android:TextView设置背景色和文本颜色
- android--设置TextView部分文字的颜色和背景(高亮显示)
- 37-TextView设置文本颜色显示
- andorid,动态设置TextView文本中字体的颜色和格式,用Html.fromHtml方法
- 转【备忘】android 文本颜色和背景的设置问题
- uitableview group的一些问题 (设置两个section之间的距离,设置背景颜色 等)在plain下去掉foot view的粘性
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)