0

我是android开发的绝对初学者。我正在尝试构建一个搜索框。所以我在我的活动上放了一个 searchview 小部件。当我运行应用程序时,它给了我这个错误。

error: 'searchBoxColor' is incompatible with attribute background (attr) 
reference|color.
error: failed linking file resources.

我无法弄清楚错误在哪里。或者我应该添加另一个文件来链接资源。

这是我的 color.xml 文件。

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <color name="colorPrimary">#3d664a</color>
        <color name="colorPrimaryDark">#00574B</color>
        <color name="colorAccent">#D81B60</color>
        <color name="backgroundColor">#e1e6e6</color>
        <color name="searchBoxColor">#d6d2d6</color>
</resources>

这是我的布局 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fillViewport="true"
     android:overScrollMode="never"
     android:scrollbars="none">

    <RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@color/backgroundColor" >

         <SearchView
              android:id="@+id/search"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:iconifiedByDefault="false"
              android:queryHint="Search Here"
              android:background="searchBoxColor"
              android:padding="6dp" >

              <requestFocus />
          </SearchView>

    </RelativeLayout>

 </ScrollView>
4

1 回答 1

1

在背景属性中添加颜色路径

android:background="@color/searchBoxColor"

它应该是

 <SearchView
          android:id="@+id/search"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:iconifiedByDefault="false"
          android:queryHint="Search Here"
          android:background="@color/searchBoxColor"
          android:padding="6dp" >
于 2018-12-27T06:38:18.057 回答