Try the following:
final Button buttonA = (Button) findViewById(R.id.ButtonA); final Button buttonB = (Button) findViewById(R.id.ButtonB); buttonA.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) {
or
make selector.xml in the drawables folder and copy the code below:
<?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/focused_pressed" /> <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pressed" /> <item android:drawable="@drawable/normal" /> </selector>
copy this code for button A in your layout
<Button android:id="@+id/buttonA" style="@drawable/test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="Button A" />
source share