9

XML is working good with:

xmlns:app="http://schemas.android.com/apk/res-auto"

but can't see max characters with

xmlns:app="http://schemas.android.com/tools"

which is completed by Android Studio auto .

Here is my XML:

<com.rengwuxian.materialedittext.MaterialEditText
    android:id="@+id/remark_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    app:met_maxCharacters="20"
    app:met_baseColor="@color/black"
    app:met_primaryColor="@color/white" />
Sufian
  • 6,405
  • 16
  • 66
  • 120
Pi Pi
  • 861
  • 3
  • 13
  • 22

1 Answers1

10

Xmlns stands for 'XML Namespace'

  • The part after ':' is the prefix for the Namespace
  • The part after '=' is the Namespace URI (the correct name for his part is actually "Namespace name").

(For further details see https://en.wikipedia.org/wiki/XML_namespace)

The namespace 'schemas.android.com/tools' is for specifying options to build the app by Android Studio, and are not included in the final app package

The namespace 'schemas.android.com/apk/res-auto' is used for all custom attributes - defined in libraries or in code. See this answer for details.

Note that any prefix can be used for a namespace, it is not mandatory to use 'app' for schemas.android.com/apk/res-auto. But the same prefix must be used when defining the custom attributes in the document, otherwise an error will be shown.

So, because met_maxCharacters is a custom attribute, it is shown when the 'schemas.android.com/apk/res-auto' namespace is used, and not with
'schemas.android.com/tools'

Community
  • 1
  • 1
Mohan Noone
  • 561
  • 6
  • 14
  • Very useful answer !Why do Android Studio use /tools rather than apk/res-auto? – Pi Pi Jul 21 '16 at 02:30
  • 2
    The two (/tools and /apk/res-auto) are for different purposes: /tools is for options used for building the app, and are not part of the app itself, and are removed in the apk. /apk/res-auto is for custom attributes which are used in the app – Mohan Noone Jul 22 '16 at 01:33
  • Very very useful answer explained in most simple terms/language – Shirish Herwade May 09 '17 at 12:51
  • 2
    @MohanNoone or you can simplify it as: the namespace `/tools` is only understood by the GUI or design tool. While the namespace `/apk/res-auto` is understood by both the apk and design tool. – Sufian Jun 18 '17 at 11:56