You can set the color of the shape and background of the button in the resource with the ability to draw and assign it as android:background in XML or setBackgroundDrawable() in the code.
Below is an example of such a button:
/res/drawable/button.xml
This file should set the rounded shape and background color
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true"> <shape android:shape="rectangle"> <solid android:color="#ffffff" /> <corners android:radius="16dp" /> <stroke android:width="3dp" android:color="#ff0000" /> </shape> </item> <item android:state_selected="true"> <shape android:shape="rectangle"> <solid android:color="#ffffff" /> <corners android:radius="16dp" /> <stroke android:width="3dp" android:color="#ff0000" /> </shape> </item> <item android:state_pressed="true"> <shape android:shape="rectangle"> <solid android:color="#ff0000" /> <corners android:radius="16dp" /> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="#ffffff" /> <corners android:radius="16dp" /> <stroke android:width="3dp" android:color="#0000ff" /> </shape> </item> </selector>
/res/color/button.xml
(This file should set the text color)
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="#0000ff" /> <item android:state_focused="true" android:color="#0000ff" /> <item android:state_selected="true" android:color="#0000ff" /> <item android:color="#000000" /> </selector>
Then you can initialize the button in your layout as:
<Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColor="@color/button" android:background="@drawable/button"/>
The wil button looks like below (by default and pressed states from top to bottom):

source share