导航:首页 > 操作系统 > android显示文字颜色

android显示文字颜色

发布时间:2023-02-22 21:32:31

1. android 如何设置webView里文字的颜色

android 设置webView里文字的颜色可以通过以下代码实现:
private String initContent(String content, boolean night, boolean flag) {
try {
InputStream inputStream = getResources().getAssets().open(
"discover.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream), 16 * 1024);
StringBuilder sBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sBuilder.append(line + "\n");
}
String modelHtml = sBuilder.toString();
inputStream.close();
reader.close();

String contentNew = modelHtml.replace(
"<--@#$%discoverContent@#$%-->", content);
if (night) {
contentNew = contentNew.replace("<--@#$%colorfontsize2@#$%-->",
"color:#8f8f8f ;");
} else {
contentNew = contentNew.replace("<--@#$%colorfontsize2@#$%-->",
"color:#333333 ;");
}
if (flag) {
contentNew = contentNew.replace(
"<--@#$%colorbackground@#$%-->", "background:#B4CDE6");
} else {
contentNew = contentNew.replace(
"<--@#$%colorbackground@#$%-->", "background:#F9BADA");
}
return contentNew;

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

2. Android中TextView中的文字颜色设置setTextColor的用法

原文链接http://blog.csdn.net/u012532559/article/details/44925285

Android 中设置TextView的颜色有方法setTextColor,这个方法被重载了,可以传入两种参数。一种方法是传入int color值,要注意这个int不是R文件中自动分配的十六进制int值,这是Color类中的静态方法构造出来的颜色int值。另一种方法是通过ColorStateList得到xml中的配置的颜色的。好多需要xml中配置的都要类似这样的映射xml文件(比如一个按钮事件的选择器,默认状态为颜色A,点击时状态为颜色B等等选择效果)。

setTextColor的两种重载方法如下:

[java] view plain

publicvoidsetTextColor(intcolor) {

mTextColor = ColorStateList.valueOf(color);

updateTextColors();

}

publicvoidsetTextColor(ColorStateList colors) {

if(colors ==null) {

thrownewNullPointerException();

}

mTextColor = colors;

updateTextColors();

}

第一种重载方法有以下实现方式:

方法一:通过ARGB值的方式

textview.setTextColor(Color.rgb(255,255, 255));

textview.setTextColor(Color.parseColor("#FFFFFF"));

方法二:通过资源引用

textview.setTextColor(mContext.getResources().getColor(R.drawable.contact_btn_text_red))

#f2497c

第二种重载方法的实现:

[java] view plain

textview.setTextColor(mContext.getResources().getColorStateList(R.drawable.big_btn_text_color));

选择器big_btn_text_color.xml

[html] view plain

3. android studio黑色主题怎么设置字体颜色

获得文本控件TextView,取名为tv。
通过TextView的setTextColor方法进行文本颜色的设置,这里可以有3种方式进行设置。
tv.setTextColor(android.graphics.Color.RED);//系统自带的颜色类。
tv.setTextColor(0xffff00ff);//0xffff00ff是int类型的数据,分组一下0x|ff|ff00ff,0x
是代表颜色整数的标记,ff是表示透明度,ff00ff表示颜色,注意:这里ffff00ff必须是8个的颜色表示,不接受ff00ff这种6个的颜色表
示。
tv.setTextColor(this.getResources().getColor(R.color.red));//通过获得资源文件
进行设置。根据不同的情况R.color.red也可以是R.string.red或者R.drawable.red,当然前提是需要在相应的配置文件里
做相应的配置。
6
通过在Activity类中设置文本颜色,我们可以实现文本颜色的动态化。如果想保持文本颜色静态不变的话,可以直接通过上一篇中讲的通过直接配置即可。

阅读全文

与android显示文字颜色相关的资料

热点内容
fw压缩图片 浏览:253
淘宝申请源码靠谱吗 浏览:870
androidupdater 浏览:635
c2d游戏源码大全可复制版 浏览:771
电脑怎样重置网关命令 浏览:411
winftplinux 浏览:335
推特app界面如何设置成中文 浏览:452
太空工程师转子编程属性 浏览:32
windowscmd关机命令 浏览:342
云桌面只要服务器装一套软件 浏览:247
电脑右键按到什么导致文件夹全屏 浏览:454
我的世界如何制造服务器主城 浏览:365
linuxssh连不上 浏览:297
永宏plc用什么编程电缆 浏览:371
win激活命令行 浏览:886
新手学电脑编程语言 浏览:893
云空间在哪个文件夹 浏览:926
编程游戏小猫抓小鱼 浏览:790
安卓dosbox怎么打开 浏览:774
服务器无影响是怎么回事 浏览:958