android在代码中四种设置控件背景颜色的方法(包含RGB)
2024-09-30 11:16:27
转载请注明出处: 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>*/
最新文章
- Git初使用
- Golang 绘图基础- 不同的输出源
- 2016年辛星less教程发布了
- 【HDOJ】4544 湫湫系列故事——消灭兔子
- ubuntu 右键新建文档
- 如何优化cocos2d/x内存使用和程序大小的程序
- Canvas:时钟
- 移植 iperf 网络性能测试工具到 Android-P
- anaconda虚拟环境管理,从此Python版本不用愁
- 通过PropertyDescriptor反映射调用set和get方法
- Ubuntu14.04 + Text-Detection-with-FRCN(CPU)
- 利用JavaMail发送邮件:smtp.163.com
- J1850 Implement
- 获取Java正在执行的方法
- python中的logger模块详细讲解
- laravel 的passport Oauth 认证登录请求 的 oauth_token 重置
- day18-事务与连接池 1.复习
- I would I were a careless child
- [Django笔记] Apache + mod-wsgi 环境部署所遇到的各种问题总结
- 洛谷P2534 [AHOI2012]铁盘整理