我正在使用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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句