Android 如何在 imageview 中组合按钮
How to combine button in imageview in Android
我想制作类似智能家居应用的应用。但是我遇到了一些问题,其中一个是如何让草图与按钮结合,所以如果按下灯按钮(黄色图标)就会显示 "the light was on"。
带按钮的房子草图:
有人能帮帮我吗?
谢谢
我建议您为 ImageView
.
的 src
属性分配一个 selector(可绘制状态列表)
例如:
your_selector_xml
文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/ic_yellow_lamp"
android:state_focused="true" />
<item
android:drawable="@drawable/ic_yellow_lamp"
android:state_pressed="true"/>
<item android:drawable="@drawable/ic_default_lamp" />
</selector>
你的ImegeView
<ImageView
....
android:src="@drawable/your_selector_xml"/>
我想制作类似智能家居应用的应用。但是我遇到了一些问题,其中一个是如何让草图与按钮结合,所以如果按下灯按钮(黄色图标)就会显示 "the light was on"。
带按钮的房子草图:
有人能帮帮我吗?
谢谢
我建议您为 ImageView
.
src
属性分配一个 selector(可绘制状态列表)
例如:
your_selector_xml
文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/ic_yellow_lamp"
android:state_focused="true" />
<item
android:drawable="@drawable/ic_yellow_lamp"
android:state_pressed="true"/>
<item android:drawable="@drawable/ic_default_lamp" />
</selector>
你的ImegeView
<ImageView
....
android:src="@drawable/your_selector_xml"/>