首页 技术 正文
技术 2022年11月15日
0 收藏 997 点赞 5,089 浏览 1122 个字

1. Android设置文本颜色的4种方法:

(1)利用系统自带的颜色类:

tv.setTextColor(android.graphics.Color.RED);

(2)数字颜色表示:

tv.setTextColor(0xffff00ff);

(3)自定义颜色:

 <?xml version="1.0" encoding="utf-8"?>
<resources> <drawable name="dkgray">#80808FF0</drawable> <drawable name="yello">#F8F8FF00</drawable>
<drawable name="white">#FFFFFF</drawable>
<drawable name="darkgray">#938192</drawable>
<drawable name="lightgreen">#7cd12e</drawable>
<drawable name="black">#ff000000</drawable>
<drawable name="blue">#ff0000ff</drawable>
<drawable name="cyan">#ff00ffff</drawable>
<drawable name="gray">#ff888888</drawable>
<drawable name="green">#ff00ff00</drawable>
<drawable name="ltgray">#ffcccccc</drawable>
<drawable name="magenta">#ffff00ff</drawable>
<drawable name="red">#ffff0000</drawable>
<drawable name="transparent">#00000000</drawable>
<drawable name="yellow">#ffffff00</drawable>
</resources>

根据个人需要,颜色可以自行添加。 

在Java中设置: 

tx.setTextColor(tx.getResources().getColor(R.drawable.red)); 

color.xml中也可用color标签:

<color name=”red”>#ffff0000</color>     

Java中设置相应改为: 

tx.setTextColor(tx.getResources().getColor(R.color.red));

(4)直接在xml的TextView中设置:

android:textColor=”#f8f8ff00″

或者

android:textColor=”#f8ff00″

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,030
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,147
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859