Androidでのボタン(Button)をクリックしていた時のカスタマイズ方法

1.drawableの下にselector.xmlを置く

<?xml version="1.0″ encoding="utf-8″?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/temp1″ />
<item android:state_pressed="false" android:state_focused="false"
android:drawable="@drawable/temp2″ />
<item android:state_focused="true" android:drawable="@drawable/temp3″ />
<item android:state_focused="false" android:drawable="@drawable/temp4″ />
</selector>

2.レイアウトファイルmain.xml
<?xml version="1.0″ encoding="utf-8″?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:drawableTop="@drawable/shouru"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button"
android:background="@drawable/selector"/>
</LinearLayout>

Android

Posted by arkgame