Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between android: and app: prefix in Android XML?

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.

like image 769
Arturs Vancans Avatar asked Apr 19 '15 16:04

Arturs Vancans


People also ask

What is XML app android?

eXtensible Markup Language, or XML: A markup language created as a standard way to encode data in internet-based applications. Android applications use XML to create layout files. Unlike HTML, XML is case-sensitive, requires each tag be closed, and preserves whitespace.

What is app namespace?

The app namespace is not specific to a library, but it is used for all attributes defined in your app, whether by your code or by libraries you import, effectively making a single global namespace for custom attributes - i.e., attributes not defined by the android system.

Is XML required for app development?

Java and XML are the two main programming languages used in Android App development. Knowledge and mastery over these programming languages are, therefore, prerequisites to developing an Android app.


2 Answers

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

like image 50
Gaëtan Avatar answered Oct 13 '22 02:10

Gaëtan


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.

like image 29
Bojan Kseneman Avatar answered Oct 13 '22 03:10

Bojan Kseneman