Reputation: 4640
What is the difference and more importantly the necessity of having different prefixes in Andriod view XML?
For example,
<android.support.v7.widget.Toolbar
android:id="@+id/actionToolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentInsetEnd="20dp"
app:contentInsetEnd="20dp"
android:elevation="3dp"
/>
Has contentInsetEnd
for both android
and app
.
Upvotes: 50
Views: 15118
Reputation: 15668
app namespace is used for custom defined attributes, which are usually defined in /values/attrs.xml
Here is a sample of such file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SimpleTabIndicator">
<attr name="numberOfTabs" format="integer"/>
<attr name="indicatorColor" format="color"/>
</declare-styleable>
</resources>
And a sample usage would be
<com.someapp.demo.SimpleTabIndicator
android:id="@+id/tabIndicator"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#26292E"
app:indicatorColor="#FFFDE992"
app:numberOfTabs="5"/>
Android namespace you use for Android's widgets and UI controls.
Upvotes: 15
Reputation: 12552
android
is usually used for attribute coming from Android SDK itself.
app
is often used if you are using the support library.
You may also see other namespaces if you are using custom views (of your own or form a library).
Here is some extra information: http://developer.android.com/training/custom-views/create-view.html#customattr
Upvotes: 49
Reputation: 9050
app
is just a namespace for any custom parameters for a custom View.
This can be anything but if you see the root element there's probably a line xmlns:app="http://schemas.android.com/apk/res-auto"
that assigns the namespace .
Upvotes: 11