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

后端 未结 4 1860
情深已故
情深已故 2020-12-03 00:59

What is the difference and more importantly the necessity of having different prefixes in Andriod view XML?

For example,



        
相关标签:
4条回答
  • 2020-12-03 01:10

    if you use app prefix e.g app:text="disconnected" then the text will not display when you run on a real device. if you want to display something while design but not on an actual device, you can use this prefix too.

    0 讨论(0)
  • 2020-12-03 01:14

    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

    0 讨论(0)
  • 2020-12-03 01:33

    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 .

    0 讨论(0)
  • 2020-12-03 01:34

    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.

    0 讨论(0)
提交回复
热议问题