2010-08-26 38 views
3

我正在創建自定義textview,我想爲此textview提供黑色textcolor。我如何設置textcolor。我的代碼是如何在課堂文件中將textcolor提供給textview

TextView textview = new TextView(this);

textview.setText(「請按照此說明」);

setContentView(_textview);

當我使用textview.setTextColor(的Integer.parseInt( 「#000000」))

在此先感謝

回答

4

使用Color.parseColor():

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

另一種選擇是直接使用十六進制整數:

textview.setTextColor(0xff000000); 
+0

的代碼允許您設置不僅預定義的顏色,但在格式的任何顏色#RRGGBB或#AARRGGBB – 2010-08-26 07:19:48

+0

是的,它真的很棒的答案謝謝 – 2010-08-26 07:36:18

+0

根據這個答案我如何設置我的文本爲粗體。 – 2010-08-26 08:10:44

0

我發現它是通過使用代碼

textview.setTextColor完成的解決方案(Color.BLACK);