Android control code for displaying power

The following describes the control code for Android to display power. The specific code is as follows:

1. Directory structure, I use Android.

2. In the operation interface, enter the value in the input box and click refresh to display the corresponding power in the battery

3. To draw a custom battery control, first, create a new class batterystate to inherit view

Variables to use

Three construction methods. When customizing a control, these three construction methods are generally written out for easy use in layout or direct definition. Attributeset is the attribute set referenced when defining the control using an XML file

Since the control we defined is a single control, not a container control, I only rewritten onmeasure and OnDraw to calculate the size and draw the interface respectively, and calculate the area to be drawn according to the background picture

Refresh Control

4. Define in XML file:

5. Use in activity

I hope this article will help you. The control code for Android to display power is introduced here. I hope you will continue to pay attention to our website!

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
分享
二维码
< <上一篇
下一篇>>