Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

app namespace not found in styles.xml in res folder

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.

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

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> 

When compiling

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

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?

like image 833
Felix Fiskare Avatar asked Mar 01 '15 04:03

Felix Fiskare


People also ask

Where is my styles xml in Android Studio?

Defining Styles This XML file resides under res/values/ directory of your project and will have <resources> as the root node which is mandatory for the style file.

How do I find styles in xml?

xml file in the new Android Studio. Goto your project file view: Res>Values>Themes folder. Open themes. xml file change actionbar.

Where are styles created in xml?

Create and apply a style To create a new style or theme, open your project's res/values/styles. xml file. For each style you want to create, follow these steps: Add a <style> element with a name that uniquely identifies the style.

How do I create a style folder in Android?

Right click on res folder, choose New --> Android resource file, set the same name for the new file "styles", in Available qualifiers: choose the last item "Version" and finally set "Platform API level" 21. Show activity on this post.


1 Answers

You can't use an app namespace in your style file, and you should refer to style attribute wihtout app namespace in your layout.

You can do somenthing like this:

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

<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> 
like image 139
Gabriele Mariotti Avatar answered Sep 20 '22 14:09

Gabriele Mariotti