在res文件夹的styles.xml中找不到应用程序名称空间 [英] app namespace not found in styles.xml in res folder
问题描述
我正在使用android.support.v7.widget.Toolbar小部件编写自己的工具栏,我想将尽可能多的内容放入res文件夹中的styles.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?
推荐答案
您不能在样式文件中使用应用程序名称空间,而应在布局中引用style
属性,其中不包含应用程序名称空间.
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文件夹的styles.xml中找不到应用程序名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!