Reputation: 123
button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
button3.setBackgroundResource(R.color.buttonDarkSelected);
button4.setBackgroundResource(R.color.buttonMediumUnselected);
button3.setTextColor(R.color.yellow);
}
});
button4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
button4.setBackgroundResource(R.color.buttonDarkSelected);
button3.setBackgroundResource(R.color.buttonMediumUnselected);
button4.setTextColor(R.color.yellow);
}
});
}
I am trying to change Button's background and textcolor clicking in that buttons. the background is fine working fine but textcolor always black (instead I want it be yellow) what's my problem here.
Upvotes: 1
Views: 1778
Reputation: 31423
define a selector like this:
<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="#000000" />
<item android:state_focused="false" android:state_pressed="true" android:color="#000000" />
<item android:color="#ffffff" />
</selector>
save this as xml file (for example btn_text_color.xml)in your ../res/drawable/ Link it to your button like:
android:textColor="@drawable/btn_text_color"
For more details on the subject, see the link that @Kentino posted.
Upvotes: 0
Reputation: 1879
Try this:
button4.setTextColor(getApplication().getResources().getColor(R.color.yellow));
This will work to change the text color to yellow
Upvotes: 2
Reputation: 876
You can see this : http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html
With state list, you can choose differents color for button with differents state.
regards,
Upvotes: 0