当前位置:网站首页>封装仿支付宝密码输入效果
封装仿支付宝密码输入效果
2022-08-09 14:55:00 【按劳分配】
仿支付宝密码输入效果
模仿支付宝输入效果,实现很简单,就是画个矩形框和圆形,其他的通过组合view来实现所有功能,虽然简单但是封装起来,方便以后使用,也分享一下,希望对别人也有点帮助。
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,在定义使用到的属性的时候最好特别能区分开,设置特定的开头,这样能避免引入自己的工程之后导致冲突。
如有bug,谢谢指出。
边栏推荐
- 函数调用约定
- smote 采样
- For programming trading, focusing on forecast or on countermeasures?
- Talking about quantitative trading and programmatic trading
- 浏览器中的302你真的知道吗
- Suddenly want to analyze the mortgage interest rate and interest calculation
- encapsulation of strlen(), strcpy(), strncpy(), strcat(), strncat(), strcmp(), strncmp() functions
- What are the misunderstandings about the programmatic trading system interface?
- ASP.Net Core实战——身份认证(JWT鉴权)
- 如何保证电脑硬盘格式化后数据不能被恢复?
猜你喜欢
随机推荐
WebGL:BabylonJS入门——初探:注入活力
Sort method (Hill, Quick, Heap)
微信小程序tabs
地铁预约Postman脚本使用
A shortcut method for writing menu commands in C
(13)Filter过滤器
【C语言初阶】倒置字符串(输入 I like beijing. 输出beijing. like I)
ImageWatch无法显示图像
如何正确使用防关联浏览器
复数与复数域
NoUniqueBeanDefinitionException和JSON乱码处理出现异常
.Net Core 技巧小结
九、【Vue-Router】缓存路由组件 keep-alive标签
Common compilation problems
简单记录下offsetof和container_of
欢迎使用CSDN-markdown编辑器
英语议论文读写02 Engineering
Suddenly want to analyze the mortgage interest rate and interest calculation
flex布局总结
pytorch从零搭建神经网络实现多分类(训练自己的数据集)