Android Custom Properties

Source: Internet
Author: User

Values create a new Attrs.xml
<resource>
<declare-styleable name = "Mytextview" >
    <attr name= "title" Format= " String "/>
    <attr name=" switch_on "format=" string "/
&NBSP;&NBSP;&NBSP;&NBSP;</DECLARE-STYLEABLE>
</resource>

Layout file

Custom namespace   res followed by package name

xmlns:exayong= "http://schemas.android.com/apk/res/ Com.exayong.abc "

<mytextview

exayong:title=" Hello "

exayong:switch_on=" on "

/>

Mytextview.java extends Relativelayout

Construction method with properties

Attrs.getattributename (index);

//Get the custom namespace, name of the property

Attrs.getattributevalue (namespace,name);

String myTitle = Attrs.getattributevalue ("Http://schemas.android.com/apk/res/com.exayong.abc", "title");

1 Customizing a View inheritance ViewGroup

2 writing a layout file for a combined control, loading in a custom view inflate

Summarize:

The values of some properties of the own view are statically written in the layout file as a custom attribute,

Then by customizing the view inflate Findviewbyid-->view such as TextView

Get the value of a custom property by customizing the view band Attrs constructor

These values are then set to some properties of the own view, such as Textview.settext (MyTitle), through the own view method.

Android 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.