Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using App namespace in style

I am going to give an example to demonstrate the greater point.

Imagine my app has a number of FloatingActionButtons. Consequently, I want to create one style and reuse it. So I do the following:

<style name="FabStyle” parent ="Widget.Design.FloatingActionButton">     <item name="android:layout_width">wrap_content</item>     <item name="android:layout_height">wrap_content</item>     <item name="android:layout_margin">16dp</item>     <item name="app:backgroundTint">@color/accent</item>     <item name="app:layout_anchorGravity">end|bottom</item> </style> 

The problem I am having is that the code is not compiling because it is complaining about

Error:(40, 5) No resource found that matches the given name: attr 'app:backgroundTint'. 

I tried bringing the namespace in through the resources tag but that is not working

<resources     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:android="http://schemas.android.com/apk/res/android"     > 

Any ideas how I might get this to work?

like image 699
Nouvel Travay Avatar asked Sep 05 '16 18:09

Nouvel Travay


People also ask

What is App namespace?

The app namespace is not specific to a library, but it is used for all attributes defined in your app, whether by your code or by libraries you import, effectively making a single global namespace for custom attributes - i.e., attributes not defined by the android system.

Can we use CSS in Android Studio?

Yes, you read it right in the title of this article. In this article, we are going to build an Android App with HTML, CSS, and JavaScript in Android Studio.

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. Save this answer. Show activity on this post. By default, Android Studio doesn't create styles.


1 Answers

For app namespace you don't need to specify app:<property name>. Just <property name> is enough.

For example

<style name="FabStyle" parent="Widget.Design.FloatingActionButton">      <item name="android:layout_width">wrap_content</item>     <item name="android:layout_height">wrap_content</item>     <item name="android:layout_margin">16dp</item>     <item name="backgroundTint">@color/accent</item>     <item name="layout_anchorGravity">end|bottom</item> </style> 

And for layout_anchorGravity you need to set it in XML file where you are defining Floating action button.

like image 111
dex Avatar answered Oct 10 '22 18:10

dex