Go [Original] Android Custom view Password Box example

Source: Internet
Author: User
Tags border color

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

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.