ImageButton应用

来源:互联网 发布:程序员的压力大 编辑:程序博客网 时间:2024/06/15 00:08
 
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"
    />
<ImageButton android:src="@drawable/selector" android:layout_height="wrap_content" android:id="@+id/imageButton1" android:layout_width="wrap_content"></ImageButton>
<!-- android:src为图片地址 -->

</LinearLayout>


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/arrow_pressed" />
<!-- 按钮按下效果 arrow_pressed和arrow_normal 为图片文件名称 -->
<item android:state_focused="true"
  android:drawable="@drawable/arrow_pressed" />
<!-- 按钮获取焦点效果 -->
<item android:drawable="@drawable/arrow_normal" />
<!-- 按钮默认效果 -->

</selector>

原创粉丝点击