重复资源:布局、自定义视图和属性中的 android 命名空间如何工作?

问题描述

根据Google training docs on custom views

一旦定义了自定义属性,就可以在布局 XML 中使用它们 文件就像内置属性一样。唯一的区别是你的 自定义属性属于不同的命名空间。

但是当我尝试使用它时出现“错误:重复资源”。 我的布局文件看起来像:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:searchview="http://schemas.android.com
    /apk/com.kana_tutor.kana_utils.SearchView"
        xmlns:simplespinner="http://schemas.android.com
    /apk/com.kana_tutor.kana_utils.SimpleSpinner"
         ...>
    
        <com.kana_tutor.kana_utils.SearchView
          ...
            searchview:textColor="/@color/red"
            />
    
        <com.kana_tutor.kana_utils.SimpleSpinner
            ...
            simplespinner:textColor="@color/textview_background"
            />
        ...

我将属性放在两个单独的文件中: searchview_attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="SearchView">
        <attr name="textColor" format = "reference" />
    </declare-styleable>
</resources>

simplespinners_attrs:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="simplespinner">
        <attr name="textColor" format = "reference|string" />
    </declare-styleable>
</resources>

但是 IDE 说:

[attr/textColor] /.../simplespinner_attrs.xml [attr/textColor] /.../searchview_attrs.xml:错误:重复资源

当我阅读文档时,我应该能够理解“属于不同的命名空间”还是我的代码有问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)