如何在Android中获取当前的Button文本颜色?

时间:2011-06-02 05:00:53

标签: android button

我无法弄清楚如何获取Button文本的当前颜色。我知道它可能是这个,但不能完全弄清楚参数。

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

基本上我试图这样做

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

我知道如何设置文字颜色。

1 个答案:

答案 0 :(得分: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;

}