Imitation Alipay input effect, the implementation is very simple, is to draw a rectangular box and circle, the other through the combination of view to achieve all the functions, although simple but packaged up, convenient later use, but also share, hope to others also a little help.
1, how to use, you can set their own into the exit animation, do not set the animation effect, I think the package is still very good.
Private Myinputpwdutil Myinputpwdutil;
@Override
protected void onCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.activity_main);
Myinputpwdutil = new Myinputpwdutil (this);
Myinputpwdutil.getmyinputdialogbuilder (). Setanimstyle (R.style.dialog_anim);//can customize itself into the exit animation without setting no animation
Myinputpwdutil.setlistener (New Inputpwdview.inputpwdlistener () {
@Override public
Void Hide () {
Myinputpwdutil.hide ();
}
@Override public
void Forgetpwd () {
toast.maketext (mainactivity.this, "Forgotten password", toast.length_short). Show ();
@Override public
void Finishpwd (String pwd) {
toast.maketext (mainactivity.this, PWD, toast.length_ Short). Show ();
}} public void Show (view view) {
myinputpwdutil.show ();
}
2, the input box implements the main code, which is to draw the rectangle and the middle circle.
int height = getheight ();
int width = getwidth ();
Draw Border RECTF rect = new RECTF (0, 0, width, height);
Borderpaint.setcolor (bordercolor);
Canvas.drawroundrect (Rect, Borderradius, Borderradius, Borderpaint); Picture content area RECTF rectcontent = new RECTF (Rect.left + defaultcontentmargin, Rect.top + defaultcontentmargin, Rect.right-defa
Ultcontentmargin, Rect.bottom-defaultcontentmargin);
Borderpaint.setcolor (Getresources (). GetColor (R.color.myinputpwdbase_gray));
Canvas.drawroundrect (Rectcontent, Borderradius, Borderradius, Borderpaint);
Draw dividing line: The number of split lines is less than 1 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);
///Draw password content float px, py = HEIGHT/2;
float Halfwidth = WIDTH/PASSWORDLENGTH/2; for (int i = 0; i < textlength i++) {px = width * i/passwordlength + halfwidth; canvas.drawcircle (px, py, PASSWORDW
Idth, Passwordpaint); }
3, as a module of the library, the best way to define the attributes to use is to separate them and set a specific opening so that you can avoid conflicts after you introduce your own project.
The above is a small set to introduce the Android imitation Alipay password input box effect, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!