Compliance Guidelines
Exposes all properties or behaviors that affect the visible appearance in your view.
- Adding and setting styles through XML
- Control the appearance and behavior of elements through their attributes, and support event listeners that communicate with important events
For detailed steps see: Android Custom View Step
Like
Supported Styles
Attributes that can affect the outer and behavior through XML definitions are as follows
Border fillet value, border color, split line color, border width, password length, password size, password color
<declare-styleablename= "Passwordinputview"> <attrname= "BorderWidth"format= "Dimension"/> <attrname= "BorderColor"format= "Color"/> <attrname= "Borderradius"format= "Dimension"/> <attrname= "Passwordlength"format= "integer"/> <attrname= "Passwordwidth"format= "Dimension"/> <attrname= "Passwordcolor"format= "Color"/> <attrname= "Passwordradius"format= "Dimension"/></declare-styleable>
At the same time support the original EditText function, you can get data values, digital keyboard settings, etc.
Main code for plotting logic
protected voidOnDraw (canvas canvas) {intwidth =getwidth (); intHeight =getheight (); //Outer frameRECTF rect =NewRECTF (0, 0, width, height); Borderpaint.setcolor (bordercolor); Canvas.drawroundrect (Rect, Borderradius, Borderradius, Borderpaint); //Content AreaRECTF Rectin =NewRECTF (Rect.left + defaultcontmargin, Rect.top +Defaultcontmargin, Rect.right-Defaultcontmargin, Rect.bottom-defaultcontmargin); Borderpaint.setcolor (Color.White); Canvas.drawroundrect (Rectin, Borderradius, Borderradius, Borderpaint); //Split LineBorderpaint.setcolor (bordercolor); Borderpaint.setstrokewidth (Defaultsplitlinewidth); for(inti = 1; i < passwordlength; i++) { floatx = width * I/passwordlength; Canvas.drawline (x,0, x, Height, borderpaint); } //Password floatCX, cy = HEIGHT/2; floatHalf = WIDTH/PASSWORDLENGTH/2; for(inti = 0; i < textLength; i++) {CX= width * I/passwordlength +half; Canvas.drawcircle (CX, CY, Passwordwidth, Passwordpaint); }}
Full code Download
Https://github.com/tianshaojie/Android-PasswordInputView
Go [Original] Android Custom view Password Box example