這是我第一篇文章。 我必須在運行時更改TextView's
文字顏色。有一種方法TextView.setTextColor(int)
,但它不適用於不在資源中的int值。
例如,在運行時計算出的顏色(如0xFF0000 (RGB)
,不存在於R.color
中)不起作用。 TextView
未呈現。
我已經採取了看看這個Android源代碼,並有兩種方法,他們沒有接受rgb int values
作爲參數:TextView:無法在運行時更改文字顏色
/**
* Sets the text color for all the states (normal, selected,
* focused) to be this color.
*
* @attr ref android.R.styleable#TextView_textColor
*/
@android.view.RemotableViewMethod
public void setTextColor(int color) {
mTextColor = ColorStateList.valueOf(color);
updateTextColors();
}
/**
* Sets the text color.
*
* @attr ref android.R.styleable#TextView_textColor
*/
public void setTextColor(ColorStateList colors) {
if (colors == null) {
throw new NullPointerException();
}
mTextColor = colors;
updateTextColors();
}
所以沒有這樣做的呢?也許延伸TextView
?
在此先感謝。
問題是什麼?通過使用android.graphics.Color類中的常量和方法,可以在UI線程中的任何位置設置文本顏色。 –