如何在Android中获取当前的Button文本颜色? [英] How to get current Button text color in Android?

查看:52
本文介绍了如何在Android中获取当前的Button文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I cant figure out how to get the current color of the text of a Button. I know its probably this but cant quite figure out the parameters.

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

基本上我正试图这样做

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

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

I know how to set the text color.

推荐答案

尝试一下

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;

}

这篇关于如何在Android中获取当前的Button文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆