[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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>