Подтвердить что ты не робот

Пространство имен приложений не найдено в styles.xml в папке res

Я пишу собственную панель инструментов с виджетами android.support.v7.widget.Toolbar, и я хочу поместить как можно больше в файл styles.xml в папке res.

Часть файла в файле /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" >

my "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'.

Если я использую значения app: * в $example.xml, все работает нормально. Поэтому, как я могу использовать пространство имен приложений в файлах в папке res?

4b9b3361

Ответ 1

Вы не можете использовать пространство имен приложений в своем файле стиля, и вы должны ссылаться на пространство имен приложения tt > app wihtout в своем макете.

Вы можете сделать somenthing следующим образом:

<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>

Ответ 2

Используйте Android замените app в файле стиля:

<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="android:theme">@style/ThemeOverlay.AppCompat.Dark</item>
   <item name="android:popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
   <item name="android:contentInsetStart">0dp</item>
</style>