Android Custom View Password box instance code _android

Source: Internet
Author: User
Tags border color

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); }
} 

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.