[Android] properties of mobile guard custom control
The custom combination control completed in the previous section is not flexible enough. In the display information of the control, follow the system properties and customize their own properties
In the previous section, there are three controls in the composite control settingitemview: textview header, textview description, Check@R_ 572_ 2419 @ check box
Custom attributes TSH: title = "headline" and TSH: desc_ On = "subtitle on", TSH: desc_ Off = "subtitle off"
Add namespace, xmlns: TSH = "" http://schemas.android.com/apk/res/ Package name“
Create the attrs.xml file in the RES / values / directory
Add node < declare styleable name = "textview" >
Add a node < attr name = "title" format = "string" / > under the node, and add nodes of the other two attributes
When the layout file is used, the constructor with two parameters will be called
In this constructor, an attributeset object will be passed
Call getattributevalue() method of attributeset object to get the attribute value. Parameter: index position, not recommended
Call getattributevalue (namespace, name) method of attributeset object, parameters: namespace, attribute name
Call the settext () method of the textview object and set it directly
In the description part, in the setchecked () method, judge and then set
SettingItemView.java
activity_ setting.xml
attrs.xml