2017-02-25 70 views
0

我有一個TextView和其默認的顏色,以獲得從偏好的新的文字顏色設置爲無法設置TEXTCOLOR與ColorDrawable

textView.setTextColor(Color.BLACK); 

現在,我做了以下內容:

textcolor = Color.BLACK; 
SharedPreferences sharedPreferences5 = android.preference.PreferenceManager.getDefaultSharedPreferences(this); 
textcolorpri = sharedPreferences5.getInt("tabletextcolor", textcolor); 

但我不能設置這種顏色的文本,得到一個錯誤與下面的代碼

textView.setTextColor(new ColorDrawable(textcolorpri)); 

回答

1

setTextColor預計顏色作爲int

new ColorDrawable將創建一個Drawable這是一個對象。


如果你想使用的顏色,只需使用textView.setTextColor(textcolorpri);

另見documentation here

+0

我不知道我什麼時候開始嘗試它,它並沒有更早的工作,現在在我們的指導下,它的工作就像。 – Panache