Android Custom View Typearray

Source: Internet
Author: User

When defining the view, we can use the system-provided properties, or customize some additional properties to set the custom view style, which we need to typearray, literally means the type array.

Today we'll talk about how to customize the properties of the view.

Typearray is used in conjunction with XML files, and in Android, many are used in conjunction with XML files.

We create a attr.xml file under the Res/value path, which can contain several sets of attributes. 】

<?xml version= ' 1.0 ' encoding= "Utf-8"?>


<declare-styleable name= "MyView" >

<attr name= "Mytextsize" format= "Dimension"/> format is data type

<attr name= "MyColor" format= "Color"/>



In the constructor, by Typearray ta = context.obtainstyledattributes (attrs,r.styleable.myview,defstyle,0);

This obtains the property collection and then obtains the property values that the custom control sets on the page during use by invoking the method provided by the TA. The purpose here is to get these property values, which are used when drawing the custom view.

After obtaining these values, you must call the Ta.recycle () method to recycle.

Android Custom View Typearray

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