Current location - Education and Training Encyclopedia - Education and training - Sharing computer training of Android custom controls
Sharing computer training of Android custom controls
First, a simple custom control MyButton.

Each control is a java class with corresponding code. As long as you can write java code correctly, computer training found that you can create a control that meets your needs, that is, a custom control.

1. Create a custom control through inheritance.

Rewrite the rendering of the interface by inheriting existing controls.

By inheriting a layout with several child controls

Override the response event by inheriting the existing control.

Inherit a view to completely customize a heart control.

2. Let your custom control inherit the latest Android control, and it must be public.

The constructor of the parent class is usually called. Note that there are usually three constructors.

Overwrite the method of the original control, and pay attention to whether to call the method in super again.

Reference this control as the full name of the class in XML.

Second, the complex custom control MyLogin.

If you need to design a custom control that contains a set of controls, you need to use complex custom controls.

1)? Let your custom control inherit from the closed layout.

2)? Correct construction method: Instantiate the target layout in the construction method and find all sub-layouts at the same time.

3)? Add the corresponding response code to modify the property so that the child controls in the layout can be accessed externally.

4)? Reference this control in XML as the full name of the class, complete package name+class name.