我正在使用 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
属性而不需要应用命名空间。
你可以这样做:
<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>
关于android - 在 res 文件夹的 styles.xml 中找不到应用命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28790055/