공부/Android
안드로이드 커스텀 버튼
Lim.JeiKei
2011. 1. 4. 09:52
헐 이렇게 쉽게 커스텀 버튼이 가능하다니....
Drawable.에서 xml 파일 하나 만들어서 Button 사용하는 레이아웃에서 backgournd로 지정하면 끝난다.
Drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/mach_selection_menu_default_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/mach_selection_menu_default_selected" /> <!-- focused -->
<item android:drawable="@drawable/mach_selection_menu_default_normal" /> <!-- default -->
</selector>
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/copybutton"
android:text = "Copy"
android:background="@drawable/mach_selection_menu_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
</LinearLayout>
Drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/mach_selection_menu_default_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/mach_selection_menu_default_selected" /> <!-- focused -->
<item android:drawable="@drawable/mach_selection_menu_default_normal" /> <!-- default -->
</selector>
Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/copybutton"
android:text = "Copy"
android:background="@drawable/mach_selection_menu_default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
</LinearLayout>