在ImageButton-Android中设置背景颜色并设置背景上的图像

在ImageButton-Android中设置背景颜色并设置背景上的图像,android,background-image,transparency,imagebutton,Android,Background Image,Transparency,Imagebutton,我需要设置一个背景色和背景上的图像,我怎么做?图像是否需要透明?我也需要控制状态:压力,专注 任何帮助都将不胜感激是的,图像需要透明背景,否则将覆盖背景色。对颜色使用background属性,对图像使用src。另外,请查看。对于按下的状态,使用谷歌 是,图像需要透明背景,否则将覆盖背景色。对颜色使用background属性,对图像使用src。另外,请查看。对于按下的状态,使用谷歌 创建一个ImageView(对src图像使用透明的.PNG): res/layout/yourlayout.xml

我需要设置一个背景色和背景上的图像,我怎么做?图像是否需要透明?我也需要控制状态:压力,专注


任何帮助都将不胜感激

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

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

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

res/layout/yourlayout.xml


res/drawable/colorstates.xml


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

res/layout/yourlayout.xml


res/drawable/colorstates.xml


<ImageView
    android:layout_width=:"wrap_content"
    android:layout_height=:"wrap_content"
    android:background="@drawable/colorstates"
    android:src="@drawable/image" />
<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>