50

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.

Arturs Vancans
  • 4,531
  • 14
  • 47
  • 76

3 Answers3

48

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

Gaëtan
  • 11,912
  • 7
  • 35
  • 45
  • Thanks. But I don't understand a special case, what is difference between constraint_layout properties in app namespace (e.g. app:layout_constraintStart_toStartOf ) and in card_view namespace (e.g. card_view:layout_constraintStart_toStartOf) for a widget when we use it in cardview? – Reyhane Farshbaf Nov 26 '19 at 08:59
14

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.

Bojan Kseneman
  • 15,488
  • 2
  • 54
  • 59
11

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 .

inmyth
  • 8,880
  • 4
  • 47
  • 52