1

我需要在该背景上设置背景颜色和图像,我该怎么做?图像是否必须具有透明度?我也需要控制状态:按下、聚焦。

任何帮助将不胜感激

4

2 回答 2

6

创建一个 ImageView(为您的 src 图像使用透明的 .PNG):

资源/布局/yourlayout.xml

<ImageView
    android:layout_width=:"wrap_content"
    android:layout_height=:"wrap_content"
    android:background="@drawable/colorstates"
    android:src="@drawable/image" />

res/drawable/colorstates.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/regular"
        android:state_checked="true"
        android:state_pressed="true" />
    <item
        android:drawable="@drawable/pressed"
        android:state_pressed="true" />
    <item
        android:drawable="@drawable/pressed"
        android:state_checked="true" />
    <item
        android:drawable="@drawable/regular" />
</selector>
于 2013-10-03T23:30:27.827 回答
0

是的,图像需要透明背景,否则它将覆盖背景颜色。使用颜色和图像的background属性。src另请查看文档。对于按下状态,使用谷歌!

于 2013-10-03T23:28:29.680 回答