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"?>
<resource>
<declare-styleable name= "MyView" >
<attr name= "Mytextsize" format= "Dimension"/> format is data type
<attr name= "MyColor" format= "Color"/>
</declare-styleable>
</resource>
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