ImageButton应用
16lz
2021-01-23
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>
<?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>
更多相关文章
- Android 如何加载大图片
- Android 图片加载库Glide
- android 自定义图片剪裁
- Android DrawerLayout抽屉效果
- Android——ImageButton【图片按钮】的点击事件与属性
- android 选择本地图片并预览
- Android 实现文件(图片)上传
- Android对话框图片全屏