6

I am extracting styles for views which are inside Support Library's GridLayout.

Therefore, I have both attributes from the "android" namespace, e.g. android:layout_marginLeft="8dp" and attributes from the "app" (http://schemas.android.com/apk/res-auto) one, e.g. app:layout_columnSpan="2".

First, Android Studio doesn't recognize the attributes from "app" when I try to extract the attributes as a style. Second, it doesn't seem that extracting them into styles.xml manually brings any effect to the actual layout. So, is it possible to extract the Support Library attributes as a separate style, and how?

nekojsi
  • 1,423
  • 2
  • 13
  • 28
  • 1
    Are you using gradle build? Am I right that you have compilation error? Or Android Studio complaints/highlights these lines? – Eugen Martynov Jan 08 '14 at 14:33
  • Yes, I am using Gradle build, and correct, there are compilation errors. I just noticed that the attributes are ignored in Design mode previously, but the result is nevertheless the same - "app" attributes are not working. – nekojsi Jan 08 '14 at 15:49
  • 1
    Did you add schema to your xml? – Eugen Martynov Jan 08 '14 at 19:11
  • Which XML? If you mean the layout XML, I have been extracting the attributes out of a working file, so yes, the XML namespace has been defined there already. I have also tried the same thing in the styles XML, but without success. – nekojsi Jan 08 '14 at 19:31
  • In meantime, as this [similar question](http://stackoverflow.com/questions/6860886/custom-attributes-in-styles-xml) has been answered, the custom attributes should have no namespace prefix and they will be recognized. That worked for me, so I am going to post it as an answer. – nekojsi Jan 08 '14 at 19:47

1 Answers1

12

I have found this answer to a similar question. The same solution worked for me.

Just leave out the namespace prefix for the non-"android" attributes:

app:layout_columnSpan="2" in the layout becomes

<item name="layout_columnSpan">2</item> in the styles, and not

<item name="app:layout_columnSpan">2</item>

Community
  • 1
  • 1
nekojsi
  • 1,423
  • 2
  • 13
  • 28