android - 在 res 文件夹的 styles.xml 中找不到应用命名空间

标签 android android-studio android-appcompat

我正在使用 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/

相关文章:

Android 用 xml 中的另一个线性布局替换线性布局

java - 我需要将 .so 文件复制到 System/libs 吗?

android - Edittext 颜色在 appcompat 22.2 中为白色

android - 使用 AppCompat-v7 21 在操作栏/工具栏中显示图标

android - 当我将一些值插入小部件数据库时小部件没有更新

java - 使用 Phonegap 在 Eclipse for Android 中进行开发。 'Untagging Socket' 错误=-13

java - 如何仅使用应用程序打开文件

安卓工作室断言错误: Don't invoke waitForSmartMode from inside read action in dumb mode

android - 我如何在 android studio 的矢量 Assets 中修复 NOTHING TO SHOW

android - 如何使用 Kotlin 从内部 fragment_name.kt 源文件访问 supportActionBar