What's the difference between "?android:" and "@android:" in an android layout xml file? They seem to be interchangeable ways of reusing android SDK resources.
The only difference I discovered is illustrated by the following example.
Here the TextView's right edge is rendered aligned with the left edge of the ImageButton
<RelativeLayout android:id="@id/header" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#888888"> <TextView android:id="@android:id/text1" android:layout_alignParentLeft="true" android:text="blah blah" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@android:id/button1" /> <ImageButton android:id="@android:id/button1" android:layout_alignParentRight="true" style="@style/PlusButton" /> </RelativeLayout>
Here, however, the right edge of the TextView is aligned with the right edge of the RelativeLayout. The TextView overlaps the ImageButton.
<RelativeLayout android:id="@id/header" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#888888"> <TextView android:id="@android:id/text1" android:layout_alignParentLeft="true" android:text="blah blah" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toLeftOf="?android:id/button1" /> <ImageButton android:id="?android:id/button1" android:layout_alignParentRight="true" style="@style/PlusButton" /> </RelativeLayout>
The only difference between the two layouts is the use of @android vs ?android. Both compile with no errors.
Thanks much.
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). Thanks.
XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.
Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements. Each layout file must contain exactly one root element, which must be a View or ViewGroup object.
Prefixing the ID with a question mark indicates that you want to access a style attribute that's defined in a style theme, rather than hard-coding the attribute.
See "Referencing Style Attributes" here: accessing-resources
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