1

I tried just setting android:textColor="#FFFFFF" and this didn't work so I checked other answers to the problem to find solutions.

I tried making a selector and then setting the android:textColor attribute to this selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:color="#ffffff" />
<item android:state_focused="true" android:state_pressed="true" android:color="#ffffff" />
<item android:state_focused="false" android:state_pressed="true" android:color="#ffffff" />
<item android:color="#ffffff" />
</selector>

That didn't work either.

I tried setting the text color programmatically: verifyButton.setTextColor(getApplication().getResources().getColor(R.color.white));

That didn't work either. The button text color is a dark grey and I can't seem to change it to white.

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58
Questioner
  • 2,451
  • 4
  • 29
  • 50

3 Answers3

2

You can try with

setTextColor(Color.parseColor("#FFFFFF"));

FYI

Why calling getApplication() ?

getApplication() is only available on the Activity class and in the Service class, whereas getApplicationContext() is declared in the Context class.

  • You should call getApplicationContext() instead of getApplication() .

    setTextColor(getApplicationContext().getResources().getColor(R.color.white));

You should call getApplicationContext() or Direct Activity Class .

Return the context of the single, global Application object of the current process.

getApplication() vs. getApplicationContext()

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Today, I also encountered this problem. I found that I set hint="AAA" for Button and then set textColor. This is invalid, it only works for text. I should set textColorHint to help those who have experienced this minor problem

0

Don't use getApplication(). Use getContext() instead. Or use ContextCompat.getColor() for backward compatibility