導航:首頁 > 操作系統 > 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顯示文字顏色相關的資料

熱點內容
當通過ssh遠程連接彈性雲伺服器時 瀏覽:654
12306哪個app 瀏覽:679
免費網站電視劇電影全免費在線觀看 瀏覽:737
如何快速清除app廣告 瀏覽:716
單片機按鍵外部中斷 瀏覽:560
單片機的usb供電 瀏覽:256
更改android解析度 瀏覽:186
phpstaticfinal 瀏覽:695
成人倫理風月片電影 瀏覽:294
禁播愛情片 瀏覽:21
動漫電影免費版大全 瀏覽:14
java什麼是this 瀏覽:811
拍攝指南by小說製造機txt下載 瀏覽:738
豆瓣pdf 瀏覽:723
春宮妖姬演員表 瀏覽:112
韓國情愛電影在線 瀏覽:812
程序員那麼可愛顧墨吃醋 瀏覽:201
伺服器未測速怎麼辦 瀏覽:15
男主角林晨的都市小說 瀏覽:899
百度文庫系統源碼nodejs 瀏覽:997