这篇文章主要介绍Android如何实现仿支付宝密码输入效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
效果图
1、如何使用,可以设置自己的进入退出动画,不设置则没有动画效果,自己觉得封装之后还是非常用好的。
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);
//可以定制自己进入退出动画,不设置没有动画
myInputPwdUtil.setListener(new InputPwdView.InputPwdListener() {
@Override
public void hide() {
myInputPwdUtil.hide();
}
@Override
public void forgetPwd() {
Toast.makeText(MainActivity.this, "忘记密码", 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、输入框实现主要代码,就是绘制矩形和中间的圆形而已。
int height = getHeight();
int width = getWidth();
//画边框
RectF rect = new RectF(0, 0, width, height);
borderPaint.setColor(borderColor);
canvas.drawRoundRect(rect, borderRadius, borderRadius, borderPaint);
//画内容区域
RectF rectContent = new RectF(rect.left + defaultContentMargin, rect.top + defaultContentMargin, rect.right - defaultContentMargin, rect.bottom - defaultContentMargin);
borderPaint.setColor(getResources().getColor(R.color.myInputPwdBase_gray));
canvas.drawRoundRect(rectContent, borderRadius, borderRadius, borderPaint);
//画分割线:分割线数量比密码数少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, borderPaint);
}
//画密码内容
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, passwordWidth, passwordPaint);
}
3、作为library的module,在定义使用到的属性的时候最好特别能区分开,设置特定的开头,这样能避免引入自己的工程之后导致冲突。
以上是“Android如何实现仿支付宝密码输入效果”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。