软件编程
位置:首页>> 软件编程>> Android编程>> android仿支付宝密码输入框效果

android仿支付宝密码输入框效果

作者:zhoushenxian  发布时间:2021-08-06 12:14:01 

标签:android,支付宝,密码

本文实例为大家分享了android仿支付宝密码输入框展示的具体代码,供大家参考,具体内容如下

这个没什么好分析的,就是一些基本的绘制什么线,矩形什么的,看代码更具体

布局文件:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.example.custompasswordview.PasswordView
 android:id="@+id/passwordview"
 android:layout_width="match_parent"
 android:layout_height="105px"
 android:layout_marginTop="100px"
 android:layout_marginLeft="20px"
 android:layout_marginRight="20px"
 android:inputType="number"
 android:cursorVisible="false"
 android:focusable="true"
 android:focusableInTouchMode="true"
 android:enabled="true"
 android:clickable="true"
  />
<Button
 android:id="@+id/btn_pass_reset"
 android:layout_width="250px"
 android:layout_height="90px"
 android:text="重置"
 android:layout_below="@id/passwordview"
 android:layout_marginTop="20px"
 android:layout_marginLeft="40px"
 android:gravity="center"
 />
</RelativeLayout>

MainActivity.java


package com.example.custompasswordview;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button btn_pass_reset;
private PasswordView passwordview;
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 btn_pass_reset = (Button) findViewById(R.id.btn_pass_reset);
 passwordview = (PasswordView) findViewById(R.id.passwordview);
 btn_pass_reset.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
   passwordview.setEmpeyText();
  }
 });
}
}

自定义EditText输入框


package com.example.custompasswordview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

/**
* Created by Adminis on 2016/8/7.
*/
public class PasswordView extends EditText {
private static final String TAG ="PasswordView" ;
private Paint bordPaint;//外框画笔
private Paint linePaint;//线 的画笔
private Paint passTextPaint;//密码画笔
private int width;
private int height;
private int passwordLength = 6;//代码的长度
private int textLength;
private int radius = 15;
public PasswordView(Context context) {
 this(context,null);
}
public PasswordView(Context context, AttributeSet attrs) {
 this(context, attrs,0);
}

public PasswordView(Context context, AttributeSet attrs, int defStyleAttr) {
 super(context, attrs, defStyleAttr);
 initPaint();
}

/**
 * 初始化画笔
 */
private void initPaint() {
 setFocusable(true);
 bordPaint = new Paint();
 bordPaint.setStrokeWidth(8);
 bordPaint.setColor(Color.WHITE);
 bordPaint.setStyle(Paint.Style.FILL);

linePaint = new Paint();
 linePaint.setColor(Color.parseColor("#838B8B"));
 linePaint.setStrokeWidth(4);

passTextPaint = new Paint();
 passTextPaint.setColor(Color.parseColor("#000000"));
 passTextPaint.setStrokeWidth(12);

}

@Override
protected void onDraw(Canvas canvas) {
 super.onDraw(canvas);
 height = getMeasuredHeight();
 width = getMeasuredWidth();
 drawRoundRect(canvas);
 drawLine(canvas);
 drawTextPass(canvas);
}

/**
 * 绘制密码
 * @param canvas
 */
private void drawTextPass(Canvas canvas) {
 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, radius, passTextPaint);
 }
}

/**
 * 绘制线
 * @param canvas
 */
private void drawLine(Canvas canvas) {
 for (int i = 1; i < passwordLength; i++) {
  float x = width * i / passwordLength;
  canvas.drawLine(x, 12, x, height-12, linePaint);
 }
}
/**
 * 绘制背景
 * @param canvas
 */
private void drawRoundRect(Canvas canvas) {
  canvas.drawRoundRect(0,0,width,height,12,12,bordPaint);
}
@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
 super.onTextChanged(text, start, lengthBefore, lengthAfter);
 this.textLength = text.toString().length();
 if(textLength==6){
  Toast.makeText(getContext(),"您设置的密码为"+text,Toast.LENGTH_SHORT).show();
 }
 invalidate();
}
public void setEmpeyText(){
 setText("");
 invalidate();
}
}

效果:

android仿支付宝密码输入框效果

github:https://github.com/zhouguizhi/ZhiFuBaoPwdView

来源:http://blog.csdn.net/coderinchina/article/details/52145793

0
投稿

猜你喜欢

  • Jedis简介实际开发中,我们需要用Redis的连接工具连接Redis然后操作Redis,对于主流语言,Redis都提供了对应的客户端;提供
  • 目录不含return的执行顺序finally子句含return的执行顺序返回类型是对象类型时值的变化结论不含return的执行顺序执行顺序为
  • 上周五东西都收拾好了,然后被叫住加班,直接搞到凌晨一两点,原因是另一个项目的性能出了点问题。为此我抓包写了一下主业务流的接口,涉及到文件上传
  • 好多时候,我们都需要知道某些目录下的文件什么时候被修改、删除过等,如果能用miniFilter驱动过滤来做的话当然是最好不过了,这是内核级别
  • 0.Springboot项目创建通过https://start.spring.io/生成纯净的一个springboot工程1.引入Activ
  • 这篇文章主要介绍了Java CPU性能分析工具代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋
  • 一、文件对话框C#中共有三种文件对话框,分别用于不同的功能:(1)用于打开文件的对话框OpenFileDialog。(2)用于保存文件的对话
  • 1.SQL注入:程序向后台数据库传递SQL时,用户提交的数据直接拼接到SQL语句中并执行,从而导入SQL注入攻击。字符型注入:黑色部分为拼接
  • 背景在我们android开发中,如果需要actiivty/fragment等有状态的控件保存当前状态,由系统进行数据保存的恢复的时候比如正常
  • Maven修改打包文件名称对Maven打出的jar包名称不满意:想通过修改配置给jar包改名,查询找到了方法:pom.xml的<bui
  • 本文实例为大家分享了C#实现QQ聊天窗口的具体代码,供大家参考,具体内容如下分析需要两个TextBox,一个用于显示消息,一个用于编辑消息需
  • 文件下载这种事情是很耗时的。之前使用AsyncTask这样的异步类来做下载,然后切到后台就 * 掉。所以打算试试Service。(不过按目前那
  • Junit这种老技术,现在又拿出来说,不为别的,某种程度上来说,更是为了要说明它在项目中的重要性。 凭本人的感觉和经验来说,在项目中完全按标
  • 对于学习过C语言的朋友应该都知道,使用 malloc/calloc 等分配内存的函数时,一定要检查其返回值是否为“空指针”(亦即检查分配内存
  • 甲:听说最近java跌落神坛,python称霸武林了,你知道吗?乙:不是吧,我前几天看python怎么还是第三?丙:你们都在扯蛋,pytho
  • 本文实例讲述了java中Object类用法。分享给大家供大家参考。具体如下:1、Object类是所有java类的基类如果在类的声明中未使用e
  • C#实现修改文件的创建、修改和访问时间方法,主要是用到了File类的SetCreationTime、SetLastWriteTime、Set
  • 当我们在登录像QQ邮箱这种大多数的网站,往往在登录按键上会有下次自动登录这个选项,勾选后登录成功,在一段时间内,即便退出浏览器或者服务器重启
  • 昨天在与对端系统调接口的时候,对端系统对我们传过去的json串老是处理不了,后来查原因是应为我们传过去的json串里有json对象数组,因为
  • 要求: *  对用户输入的每个字符的值进行加密,将解密后的字符串输出 *  对用户输入的已加密字符串进行解密并
手机版 软件编程 asp之家 www.aspxhome.com