1. ImageButton
res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:gravity="center" 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="wrap_content"
        android:layout_height="wrap_content" android:text="@string/hello" />

    <ImageButton android:id="@+id/imgBtn"
    android:background="@+drawable/playbutton_click"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </ImageButton>
</LinearLayout>


res/drawable/playbutton_click.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/btn1" />
    <item android:drawable="@drawable/btn" />
</selector>

 

2. Button


 - xml
<Button
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:drawableLeft="@drawable/ic_settings"
android:drawablePadding="4dp"
android:text="Settings"
/>

- java 
Button button = new Button(mContext);
button.setText("Close");
Drawable close = Drawable.createFromPath("/data/icon/image.png");
close.setBounds(0, 0, close.getIntrinsicWidth(), close.getIntrinsicHeight());
button.setCompoundDrawables(close, null, null, null);

arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()