android在代码中四种设置控件背景颜色的方法(包括RGB)

来源:互联网 发布:制造业软件系统架构 编辑:程序博客网 时间:2024/05/17 06:48
转载请注明出处: http://blog.csdn.net/fth826595345/article/details/9208771 
TextView tText=(TextView) findViewById(R.id.textv_name);    //第1种:    tText.setTextColor(android.graphics.Color.RED);//系统自带的颜色类    // 第2种:    tText.setTextColor(0xffff00ff);//0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x是代表颜色整数的标记,ff是表示透明度,ff00ff表示颜色,注意:这里ffff00ff必须是8个的颜色表示,不接受ff00ff这种6个的颜色表示。         //第3种:    tText.setTextColor(android.graphics.Color.parseColor("#87CEFA")) ; //还是利用Color类;    //第4种:    tText.setTextColor(this.getResources().getColor(R.color.red));            /*通过获得资源文件进行设置。根据不同的情况R.color.red也可以是R.string.red或者R.drawable.red,     * 当然前提是需要在相应的配置文件里做相应的配置,如(xml 标签):     *      * <color name="red">#FF0000</color>        <drawable name="red">#FF0000</drawable>        <string name="red">#FF0000</string>*/
2 0
原创粉丝点击