0
I need to change the color of a button when it is pressed, as it could be done?
0
I need to change the color of a button when it is pressed, as it could be done?
0
buttoncolor.xml
<?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="true"
android:drawable="@drawable/bgalt" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/bgalt" />
<item android:drawable="@drawable/bgnorm" />
</selector>
Now wear it like this:
b1 = (Button) findViewById(R.id.b1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
b2.setBackgroundDrawable(getResources().getDrawable(R.drawable.whatever));
}
});
b2 = (Button) findViewById(R.id.b2);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
b1.setBackgroundDrawable(getResources().getDrawable(R.drawable.whatever));
}
});
Browser other questions tagged android button
You are not signed in. Login or sign up in order to post.
Look at this example I asked in another question, does exactly that: https://answall.com/a/260618/88202
– Caique Romero