繁体   English   中英

如何在Android中更改ImageButton的背景颜色

[英]How to change background color of ImageButton in android

我有一个搜索按钮,我希望背景颜色是浅蓝色。 这是我的ImageButton

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_search"
    android:background="@android:color/searchBlue"/>

我希望背景色是浅蓝色。 但是@android:color/searchBlue突出显示为红色。 这是我的colors.xml文件

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="loomiusBlue">#00A6FF</color>
    <color name="white">#FFFFFF</color>
    <color name="headBlue">#2196F3</color>
    <color name="searchBlue">#B3E5FC</color>
</resources>

这是错误的,因为这会在核心android资源中搜索此颜色资源,而不是您的本地资源:

android:background="@android:color/searchBlue"

如果您的color.xml中存在以下颜色,这应该可以工作:

android:background="@color/searchBlue"

如果颜色searchBlue由自己一个内部定义color.xml ,你必须使用

android:background="@color/searchBlue" 

代替。 @android将引用android资源,而不是您的资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM