Customizing composite controls and custom properties

Source: Internet
Author: User

1.declare a View object to inherit relative layout or linear layout or other viewgroup;

2, in the custom View object to rewrite its construction method, in the construction method inside the layout is initialized complete;

3, according to business needs to add some API methods, expand the custom combination of controls;

4. Expand Custom Properties:

5. Declare a namespace for the custom attribute:

Xmlns:android= "Http://schemas.android.com/apk/res/android" (the namespace that comes with the system)

xmlns:mattrs= "http://schemas.android.com/apk/res/packagename"

6.Create the Attrs.xml file under the values directory in the Res directory , declaring the properties: (refer to the SDK file platforms\android-16\data\res\values\attrs.xml)

<declare-styleable name= "Settingitemview" >

<attr name= "title" format= "string"/>

<attr name= "desc_on" format= "string"/>

<attr name= "Desc_off" format= "string"/>

</declare-styleable>

7, the layout file inside the definition of the attributes are put with (attributeset attrs) Parameters of the construction method;

8. Get Properties defined: (Get property values by namespace and property name)

Attrs.getattributevalue (string namespace, string name);

Eg: attrs.getattributevalue ("Http://schemas.android.com/apk/res/packagename", "title");

Customizing composite controls and custom properties

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.