0

After updating Android Studio to 2.3 and gradle version 3.3,

btn.setEnabled(false);

Text color on the disabled button does not gray out. Functionality is working fine but I have an issue with the text color which can be misunderstood by users. btn.setTextColor() is an option but then it can be tedious. Any other alternatives would be helpful..

Aparajita Sinha
  • 514
  • 1
  • 10
  • 21

3 Answers3

2

Try this:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- disabled state -->
  <item android:state_enabled="false" android:color="#9D9FA2" /> 
  <item android:color="#000"/>
</selector>

From: Stackoverflow

Community
  • 1
  • 1
Vüsal
  • 2,580
  • 1
  • 12
  • 31
0
if (btn.isEnabled() == true)
{
btn.setTextColor(int Color);
}
else
{
btn.setTextColor(int Color);
}

It will definitely work. You can define colors respectively.

Muhammad Saad Rafique
  • 3,158
  • 1
  • 13
  • 21
-1

try this:

from java end:

    button.setTextColor(getApplication().getResources().getColor(R.color.red)); 

or 

    button.setTextColor(0xff0000); //SET YOUR COLOR 
or

    button.setTextColor(Color.parseColor("#ff0000")); 

and in xml :

<Button android:id="@+id/mybtn" 
        android:text="text textx "  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"  
        android:textStyle="bold" 
        android:textColor="#ff0000" />  <-- SET TEXT COLOR HERE -->

Ref.: Link

Community
  • 1
  • 1