Xmlns: Android = "http://schemas.android.com/apk/res/androidis
This is the namespace of XML. With this namespace, you can use Alt +/as a prompt to prompt you about what you enter, what you should not enter, what is right, and what is wrong, it can also be understood as a syntax file. Or a syntax judge or something.
This is mainly used to identify the attributes of the control during running. If you write an error, there will be no problems, but there will be problems during running, the prompt is that you do not specify the width or anything. This does not require Internet connection.
The Android-defined xmlns is actually very simple. The syntax rules are as follows:
Add xmlns: prefix = http://schemas.android.com/apk/res/your application package path to the XML layout file that uses the custom view.
The following is a simple example:
Structure:
Myview. Java
Package kexc. myview;
Import Android. content. context;
Import Android. content. res. typedarray;
Import Android. util. attributeset;
Import Android. widget. textview;
Public class myview extends textview {
Private string mstring = "Welcome to kesion's blog ";
Public myview (context, attributeset attrs ){
Super (context, attrs );
Typedarray A = context. obtainstyledattributes (attrs,
R. styleable. myview );
Int textcolor = A. getcolor (R. styleable. myview_textcolor,
0 xffffffff );
Float textsize = A. getdimension (R. styleable. myview_textsize, 36 );
Mstring = A. getstring (R. styleable. myview_title );
Settext (mstring );
Settextsize (textsize );
Settextcolor (textcolor );
}
}
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Xmlns: test = "http://schemas.android.com/apk/res/kexc.myView"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"
/>
<Kexc. myview. myview
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Test: Title = "wo Shi text"
Test: textsize = "20px"
Test: textcolor = "# fff"
/>
</Linearlayout>
Attribute file value/attrs. xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Declare-styleable name = "myview">
<ATTR name = "textcolor" format = "color"/>
<ATTR name = "textsize" format = "dimension"/>
<ATTR name = "title" format = "string"/>
</Declare-styleable>
</Resources>
Running result: