在 res 文件夹中的 style.xml 中找不到应用程序命名空间 [英] app namespace not found in styles.xml in res folder
问题描述
我正在用 android.support.v7.widget.Toolbar 小部件编写我自己的工具栏,我想将尽可能多的内容放入 res 文件夹中的 style.xml 中.
I'm writing my own toolbar with an android.support.v7.widget.Toolbar widget and I want to put as much as possible into a styles.xml in my res folder.
/res/layout/$example.xml 中文件的一部分
Part of a file in /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
my "toolbar_dark" is defined as follows in a /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 文件夹中的文件中使用我的应用命名空间?
If I use the app:* values in $example.xml directly everything works fine. Therefore, how can I use my app namespace in files in the res folder?
推荐答案
你不能在你的样式文件中使用 app 命名空间,你应该在你的布局中引用 style
属性而没有 app 命名空间.
You can't use an app namespace in your style file, and you should refer to style
attribute wihtout app namespace in your layout.
你可以这样做:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar_show_addresses_simple"
style="@style/toolbar_dark" >
风格:
<style name="toolbar_dark" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/green</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark</item>
</style>
这篇关于在 res 文件夹中的 style.xml 中找不到应用程序命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!