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
.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With