我想在点击按钮时显示活动图像。但是,如果我没有点击,则显示正常的图像样式。我该怎么做?请帮助我。
icon_home_config.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/home_button_hover" />
<item android:state_focused="true" android:drawable="@drawable/home_button_hover" />
<item android:drawable="@drawable/home_button"/>
</selector>
答案 0 :(得分:0)
<强> ImageView的强>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/btn_background" />
btn_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_default_disabled_focused" android:state_focused="true" android:state_enabled="false"/>
<item android:drawable="@drawable/btn_default_focused" android:state_focused="true" android:state_enabled="true"/>
<item android:drawable="@drawable/btn_default_disabled" android:state_enabled="false"/>
<item android:drawable="@drawable/btn_default_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/btn_default_normal" />
</selector>
答案 1 :(得分:0)
使用此background.xml选择器&amp;把它放在可绘制的文件夹和&amp;将图像背景设置为此选择器。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/normal" android:state_focused="true"/>
<item android:drawable="@drawable/normal"/>
</selector>
OR
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@drawable/normal" />
<stroke
android:width="0dp"
android:color="@drawable/pressed" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
设置图片背景
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/background" />