Android(java)学习笔记106:Android设置文本颜色的4种方法
2024-08-28 20:00:51
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"
最新文章
- Pycharm使用问题# 程序界面出现方框字符
- 怎样实现Web控件文本框Reset的功能
- rac 11g_第二个节点重启后无法启动实例:磁盘组dismount问题
- 我给女朋友讲编程html系列(2) --Html标题标签h1
- iOS-NSOperation多线程
- PL/SQL Developer 使用中文条件查询时无数据的解决方法
- C++文件操作详解(ifstream、ofstream、fstream)
- bzoj1222: [HNOI2001]产品加工
- Swift 字符串连接
- mybatis里面的 #{}和${}
- 拦截QWebView弹出窗口
- java中String类型的相关知识
- Angular - 预加载 Angular 模块
- 【ASP.NET MVC系列】浅谈NuGet在VS中的运用
- 关于STM32的延时问题
- require &#39;./ex25&#39; can&#39;t load such file
- ArrayBlockingQueue简介
- 实验二 Java面向对象程序设计实验报告
- js---数组排序法(冒泡排序;快速排序)
- unity3d 摄像机抖动效果 CameraShake