Skip to main content

Custom XML Attributes in Libraries

Today I added a custom attribute to StickyGridHeaders to set whether headers are sticky or not. In order to use XML attributes from third party libraries in Android you need to add the a namespace URI to your XML layout.
xmlns:app="http://schemas.android.com/apk/res-auto"
The choice of what to call the namespace is up to you, just as long as it is not android. Anyway, the layout file for using StickyGridHeaders in the example is now.
<?xml version="1.0" encoding="utf-8"?>
<com.tonicartos.widget.stickygridheaders.StickyGridHeadersGridView 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/asset_grid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:padding="16dp"
    app:areHeadersSticky="true"
    tools:context=".ItemListFragment" />

Comments