android背景颜色设置的几种方法
作者:互联网
<strong><span style="color:#330033;">TextView Text=(TextView) findViewById(R.id.name); <span class="indent"> </span><span class="indent"> </span>//第1种: <span class="indent"> </span><span class="indent"> </span>Text.setTextColor(android.graphics.Color.RED);//系统自带的颜色类 <span class="indent"> </span><span class="indent"> </span>// 第2种: <span class="indent"> </span><span class="indent"> </span>Text.setTextColor(0xffff00ff);//0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x是代表颜色整数的标记,ff是表示透明度,ff00ff表示颜色,注意:这里ffff00ff必须是8个的颜色表示,不接受ff00ff这种6个的颜色表示。 <span class="indent"> </span><span class="indent"> </span> <span class="indent"> </span><span class="indent"> </span>//第3种: <span class="indent"> </span><span class="indent"> </span>Text.setTextColor(android.graphics.Color.parseColor("#87CEFA")) ; //还是利用Color类; <span class="indent"> </span><span class="indent"> </span>//第4种: <span class="indent"> </span><span class="indent"> </span>Text.setTextColor(this.getResources().getColor(R.color.red)); <span class="indent"> </span><span class="indent"> </span> <span class="indent"> </span><span class="indent"> </span> <span class="indent"> </span><span class="indent"> </span>/*通过获得资源文件进行设置。根据不同的情况R.color.red也可以是R.string.red或者R.drawable.red, <span class="indent"> </span><span class="indent"> </span> * 当然前提是需要在相应的配置文件里做相应的配置,如(xml 标签): <span class="indent"> </span><span class="indent"> </span> * <span class="indent"> </span><span class="indent"> </span> * <span class="tag"><<span class="title">color</span> <span class="attribute">name</span>=<span class="value">"red"</span>></span>#FF0000<span class="tag"></<span class="title">color</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="tag"><<span class="title">drawable</span> <span class="attribute">name</span>=<span class="value">"red"</span>></span>#FF0000<span class="tag"></<span class="title">drawable</span>></span> <span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="indent"> </span><span class="tag"><<span class="title">string</span> <span class="attribute">name</span>=<span class="value">"red"</span>></span>#FF0000<span class="tag"></<span class="title">string</span>></span>*/</span></strong>
标签:颜色,name,Text,ff00ff,几种,red,android,setTextColor 来源: https://blog.51cto.com/u_14397532/2997907