【发布时间】:2011-06-02 13:14:15
【问题描述】:
我不知道如何获取按钮文本的当前颜色。我知道它可能是这个,但不能完全弄清楚参数。
public static int getTextColor (Context context, TypedArray attrs, int def)...
基本上我正在尝试这样做
if(text is RED)
{make text BLACK}
else
{make text RED}
我知道如何设置文字颜色。
【问题讨论】:
我不知道如何获取按钮文本的当前颜色。我知道它可能是这个,但不能完全弄清楚参数。
public static int getTextColor (Context context, TypedArray attrs, int def)...
基本上我正在尝试这样做
if(text is RED)
{make text BLACK}
else
{make text RED}
我知道如何设置文字颜色。
【问题讨论】:
试试这个
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;
}
【讨论】:
getCurrentTextColor() 和getDefaultColor()?显然他们都做同样的事情!