res/values/colors.xmlファイルで、次のようにさまざまな状態の異なる色を定義します (色には独自の 16 進コードを使用してください)。
<color name="green_pressed">#ff00f000</color>
<color name="green_focused">#ff00f700</color>
<color name="green_default">#ff00ff00</color>
さまざまな状態のさまざまなドローアブルを宣言する
button_focused_green.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/green_focused" />
<!-- optional, remove if you don't want round border -->
<corners android:radius="4dp" />
</shape>
button_pressed_green.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/green_pressed" />
<!-- optional, remove if you don't want round border -->
<corners android:radius="4dp" />
</shape>
button_default_green.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/green_default" />
<!-- optional, remove if you don't want round border -->
<corners android:radius="4dp" />
</shape>
StateListDrawable
に適用される xml ファイルで宣言します。Button
button_green.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_focused_green" android:state_focused="true"/>
<item android:drawable="@drawable/button_pressed_green" android:state_pressed="true"/>
<item android:drawable="@drawable/button_default_green"/>
</selector>
Button
レイアウト xml でbackground 属性を設定します
<Button
...
android:background="@drawable/button_green"
.../>
お役に立てれば。