Exposes any properties or behaviors that affect the visible appearance in your view.
• Adding and setting styles through XML
• Control the appearance and behavior of elements by their attributes, and event listeners that support and communicate important events
Detailed steps See: Android Custom View Step
The effect chart shows:
Supported Styles
The properties that affect the outside and the behavior can be defined through an XML definition as follows
Border fillet value, border color, split line color, border width, password length, password size, password color
<declare-styleable name= "Passwordinputview" >
<attr name= "BorderWidth" format= "Dimension"/>
<attr name= "bordercolor" format= "color"/> <attr name=
"Borderradius" format= "Dimension"/>
< attr name= "passwordlength" format= "integer"/> <attr name= "passwordwidth" format=
"Dimension"/>
<attr name= "Passwordcolor" format= "color"/> <attr name=
"Passwordradius" format= "Dimension"/>
At the same time support the original EditText function, you can get data values, digital keyboard settings, etc.
main code for drawing logic
protected void OnDraw (Canvas Canvas) {int width = getwidth (); int height = getheight ();
Outer frame RECTF rect = new RECTF (0, 0, width, height);
Borderpaint.setcolor (bordercolor);
Canvas.drawroundrect (Rect, Borderradius, Borderradius, Borderpaint); Content area RECTF Rectin = new RECTF (Rect.left + defaultcontmargin, Rect.top + defaultcontmargin, Rect.right-defaultcontmargi
n, Rect.bottom-defaultcontmargin);
Borderpaint.setcolor (Color.White);
Canvas.drawroundrect (Rectin, Borderradius, Borderradius, Borderpaint);
Split Line Borderpaint.setcolor (bordercolor);
Borderpaint.setstrokewidth (Defaultsplitlinewidth); for (int i = 1; i < passwordlength i++) {float x = width * i/passwordlength; canvas.drawline (x, 0, x, height, Borde
Rpaint);
}//Password float cx, cy = HEIGHT/2;
float half = WIDTH/PASSWORDLENGTH/2; for (int i = 0; i < textlength i++) {cx = width * i/passwordlength + half; canvas.drawcircle (CX, CY, Passwordwidth,
Passwordpaint); }
}