Android Development Learning notes-Customizing the process of combining controls

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.