Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current Button text color in Android?

Tags:

android

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)...

Basically Im trying to do this

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

I know how to set the text color.

like image 724
mbwasi Avatar asked Jun 02 '11 05:06

mbwasi


1 Answers

try this

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;

}
like image 156
AjOnFire Avatar answered Oct 03 '22 05:10

AjOnFire