How do I change the text color of a Button?

Jason Ching picture Jason Ching · Jun 24, 2012 · Viewed 82.7k times · Source

How do I change the text color of a Button?

Answer

ρяσѕρєя K picture ρяσѕρєя K · Jun 24, 2012

try this:

button.setTextColor(getApplication().getResources().getColor(R.color.red)); //TAKE DEFAULT COLOR

or

button.setTextColor(0xff0000); //SET CUSTOM 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 -->