Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 按时更改图像按钮背景色_Android_Android Imagebutton - Fatal编程技术网

Android 按时更改图像按钮背景色

Android 按时更改图像按钮背景色,android,android-imagebutton,Android,Android Imagebutton,我已经看到了许多悬停上ImageButton的示例,但是它们改变了图像。我只想改变背景色 这是我的选择器- <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="#4B88F7"/> <item android:state_pressed="false" android:color

我已经看到了许多悬停上ImageButton的示例,但是它们改变了图像。我只想改变背景色

这是我的选择器-

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true" android:color="#4B88F7"/>
<item android:state_pressed="false" android:color="#121212"/>

还有我的图像按钮-

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:background="@color/actionbar_btn"
        android:src="@drawable/ic_remove" />

res/drawable/
目录中创建一个包含以下内容的文件
custom_selector.xml

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/btn_pressed"/>
    <item android:state_pressed="false" android:drawable="@color/btn_released"/>
</selector>

参见

它给出了一个例外。标记需要可绘制属性或子标记来定义drawable@reza,我编辑了我的帖子。您必须创建颜色
btn\u按下
btn\u释放
<ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="2"
    android:background="@drawable/custom_selector.xml"
    android:src="@drawable/ic_remove" />