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?

5
  • 1
    Are you using gradle build? Am I right that you have compilation error? Or Android Studio complaints/highlights these lines? Jan 8, 2014 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 8, 2014 at 15:49
  • 1
    Did you add schema to your xml? Jan 8, 2014 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 8, 2014 at 19:31
  • In meantime, as this similar question 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 8, 2014 at 19:47

1 Answer 1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.