Android fake Alipay payment password input box _android

Source: Internet
Author: User

The example of this article for you to share the Android implementation of a fake Alipay payment password input box, mainly implemented as follows:

Passwordview.java

Package Com.jackie.alipay.password; 
Import Android.annotation.TargetApi; 
Import Android.content.Context; 
Import Android.graphics.Canvas; 
Import Android.graphics.Color; 
Import Android.graphics.Paint; 
Import Android.os.Build; 
Import Android.util.AttributeSet; 
Import Android.widget.EditText; 
 
Import Android.widget.Toast; 
 /** * Created by the Administrator on 2016/10/31.  * * public class Passwordview extends EditText {private Paint mborderpaint;  Outer frame brush private Paint mlinepaint; The brush of the line private Paint mpasswordpaint; Password brush private int mpasswordtextlength; 
 Enter the length of the password private int mwidth; 
 
 private int mheight; 
 
 private static final int password_length = length of 6;//password private static final int password_radius = 15; 
 Public Passwordview {This (context, NULL); 
 Public Passwordview (context, AttributeSet attrs) {This (context, attrs, 0); } public Passwordview (context context, AttributeSet attrs, int defstyleattr) {super (Context, attrs, defstyleattr); 
 Initview (); 
 
  private void Initview () {setfocusable (true); 
  Mborderpaint = new Paint (); 
  Mborderpaint.setstrokewidth (8); 
  Mborderpaint.setcolor (Color.White); 
 
  Mborderpaint.setstyle (Paint.Style.FILL); 
  Mlinepaint = new Paint (); 
  Mlinepaint.setcolor (Color.parsecolor ("#838B8B")); 
 
  Mlinepaint.setstrokewidth (4); 
  Mpasswordpaint = new Paint (); 
  Mpasswordpaint.setcolor (Color.Black); 
 Mpasswordpaint.setstrokewidth (12); 
 
  } @Override protected void OnDraw (Canvas Canvas) {Super.ondraw (Canvas); 
  Mwidth = Getmeasuredwidth (); 
 
  Mheight = Getmeasuredheight (); 
  Drawroundrect (canvas); 
  DrawLine (canvas); 
 Drawpassword (canvas); /** * Draws rounded rectangle background * @param canvas/@TargetApi (build.version_codes. Lollipop) private void Drawroundrect (Canvas Canvas) {canvas.drawroundrect (0, 0, Mwidth, Mheight, A, mborderpain 
 
 T); /** * Draw Split Line * @param canvas * * private void DrawLine (CanVas canvas) {for (int i = 1; i < password_length; i++) {Float x = mwidth * I/PASSWORD_LENGTH; 
  Canvas.drawline (x, X, mHeight-12, mlinepaint); /** * Draw Password * @param canvas/private void Drawpassword (canvas canvas) {float cx, cy = mheight/ 
  2; 
  float half = MWIDTH/PASSWORD_LENGTH/2; 
   for (int i = 0; i < mpasswordtextlength i++) {cx = Mwidth * i/password_length + half; 
  Canvas.drawcircle (CX, CY, Password_radius, Mpasswordpaint); } @Override protected void ontextchanged (charsequence text, int start, int lengthbefore, int lengthafter) {s 
 
  Uper.ontextchanged (text, start, Lengthbefore, Lengthafter); 
 
  Mpasswordtextlength = text.tostring (). Length (); if (mpasswordtextlength = = password_length) {Toast.maketext (GetContext (), "The password you set is:" + text, Toast.length_short). Sho 
  W ();; 
 } invalidate (); 
  public void Reset () {SetText (""); 
 Invalidate (); } 
}

The effect chart is as follows:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.