Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why all attributes are prefixed?

What is the design advantage to do this

<TextView
    android:layout_width="105px"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />

and not this

<android:TextView
    layout_width="105px"
    layout_height="wrap_content"
    text="@string/hello"
    />

Is that android: prefix everywhere not a little bit to chatty?

like image 979
PeterMmm Avatar asked Aug 03 '26 15:08

PeterMmm


2 Answers

android is a namespace prefix and it is used to tell that those attributes are in the XML namespace bound to that prefix. You should have a namespace declaration somewhere in your XML document which looks like xmlns:android = "the namespace URI here". It is quite unusual to prefix attributes but it is necessary when attributes of a given XML vocabulary are found in XML elements not belonging to that vocabulary because it avoids collisions.

like image 57
Ludovic Kuty Avatar answered Aug 05 '26 08:08

Ludovic Kuty


In XML, attributes have to be prefixed in order to be in a namespace; they don't automatically pick up the namespace of the element.

like image 22
Matthew Wilson Avatar answered Aug 05 '26 08:08

Matthew Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!