【发布时间】:2015-03-01 04:21:27
【问题描述】:
我正在使用 android.support.v7.widget.Toolbar 小部件编写自己的工具栏,我想将尽可能多的内容放入我的 res 文件夹中的 styles.xml。
/res/layout/$example.xml 中文件的一部分
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar_show_addresses_simple"
app:style="@style/toolbar_dark" >
我的“toolbar_dark”定义如下 /res/values/styles.xml
<style name="toolbar_dark">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@color/myPrimary</item>
<item name="app:theme">@style/ThemeOverlay.AppCompat.Dark</item>
<item name="app:popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="app:contentInsetStart">0dp</item>
</style>
编译时
Output:
Error: No resource found that matches the given name: attr 'app:contentInsetStart'.
Error: No resource found that matches the given name: attr 'app:popupTheme'.
Error: No resource found that matches the given name: attr 'app:theme'.
如果我直接在 $example.xml 中使用 app:* 值,一切正常。 因此,如何在 res 文件夹中的文件中使用我的应用命名空间?
【问题讨论】:
-
使用 style="@style/toolbar_dark" 代替 app:style="@style/toolbar_dark"。从样式中删除应用前缀。
-
首先尝试 Atheas 的建议,因为我也从未见过带前缀的样式属性。但是,我也从来没有让带有 app 前缀的元素在样式中工作。即使在我的样式文件中添加了
xmlns:app=...命名空间声明。 -
您可以使用
android命名空间,将app替换为android -
@OneWorld 只需删除 styles.xml 中的应用命名空间就可以了 :-) 我不得不承认,我真的很困惑如何在
/res/*.xml文件中声明某些内容... -
@Athena 在样式前删除
app:是正确的声明方式,但对我的错误没有影响。
标签: android android-studio android-appcompat