Procedures for customizing a composite control
1. Customize a view in general, inherit relative layout, or linear layout viewgroup;
2. Implement the constructor method of the parent class. In general, you need to initialize the custom layout file in the constructor method;
3. According to some needs or requirements, define some API methods;
----------------------------------
4. Depending on your needs, customize the properties of the control, you can refer to the TextView property;
5. Customize the namespace, for example:
Xmlns:itheima= "http://schemas.android.com/apk/res/", "The name of the package"
Xmlns:itheima= "Http://schemas.android.com/apk/res/com.itheima.mobilesafe"
6. Customize our properties in Res/values/attrs.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<declare-styleable name= "TextView" >
<attr name= "title" format= "string"/>
<attr name= "desc_on" format= "string"/>
<attr name= "Desc_off" format= "string"/>
</declare-styleable>
</resources>
7. Use our Custom properties
For example:
Itheima:title= "Set up Automatic Updates"
Itheima:desc_on= "Set up Automatic Updates is turned on"
itheima:desc_off= "Set Automatic Update is off"
8. In our custom control with two parameters of the construction method AttributeSet Attrs Take out our property values, associated with the custom layout file corresponding to the control;
Android Development Learning notes-Customizing the process of combining controls