2011-06-02 37 views
2

我不知道如何獲取按鈕的文本的當前顏色。我知道它可能是這個,但不能完全弄清楚這些參數。如何在Android中獲取當前Button文本顏色?

public static int getTextColor (Context context, TypedArray attrs, int def)... 

基本上我試着這樣做

if(text is RED) 
{make text BLACK} 
else 
{make text RED} 

我知道如何設置文本顏色。

回答

11

試試這個

ColorStateList mList = mButton.getTextColors(); 
int color = mList.getDefaultColor(); 

switch(color) 
{ 
case Color.RED: 
mButton.setTextColor(Color.BLACK); 
break; 

case Color.BLACK: 
mButton.setTextColor(Color.RED); 
break; 

} 
+0

mButton.getTextColors()。getDefaultColor()給我-1 – 2011-06-02 05:24:44

+0

-1指Color.WHITE ... mList.getDefaultColor()返回了一個顏色的恆定值。 – 66CLSjY 2011-06-02 05:31:28

+0

很好的答案..謝謝:) – Venky 2012-12-14 05:21:31

相關問題