自定义view密码框等同于支付宝支付密码框
2016-08-19 17:03
706 查看
Android 自定义View 密码框 例子
遵从准则
样式图片链接:http://images.cnitblog.com/blog/275810/201406/201603541141956.jpg
暴露您view中所有影响可见外观的属性或者行为。
通过XML添加和设置样式
通过元素的属性来控制其外观和行为,支持和重要事件交流的事件监听器
可以通过XML定义影响外边和行为的属性如下
边框圆角值,边框颜色,分割线颜色,边框宽度,密码长度,密码大小,密码颜色
<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"/>
</declare-styleable>
同时支持原来EditText功能,可以获得数据值,数字键盘设置等
绘制逻辑的主要代码
protected void onDraw(Canvas canvas) {
int width = getWidth();
int height = getHeight();
// 外边框
RectF rect = new RectF(0, 0, width, height);
borderPaint.setColor(borderColor);
canvas.drawRoundRect(rect, borderRadius, borderRadius, borderPaint);
// 内容区
RectF rectIn = new RectF(rect.left + defaultContMargin, rect.top + defaultContMargin,
rect.right - defaultContMargin, rect.bottom - defaultContMargin);
borderPaint.setColor(Color.WHITE);
canvas.drawRoundRect(rectIn, borderRadius, borderRadius, borderPaint);
// 分割线
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 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);
}
}
完整代码下载
https://github.com/tianshaojie/Android-PasswordInputView
遵从准则
样式图片链接:http://images.cnitblog.com/blog/275810/201406/201603541141956.jpg
暴露您view中所有影响可见外观的属性或者行为。
通过XML添加和设置样式
通过元素的属性来控制其外观和行为,支持和重要事件交流的事件监听器
可以通过XML定义影响外边和行为的属性如下
边框圆角值,边框颜色,分割线颜色,边框宽度,密码长度,密码大小,密码颜色
<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"/>
</declare-styleable>
同时支持原来EditText功能,可以获得数据值,数字键盘设置等
绘制逻辑的主要代码
protected void onDraw(Canvas canvas) {
int width = getWidth();
int height = getHeight();
// 外边框
RectF rect = new RectF(0, 0, width, height);
borderPaint.setColor(borderColor);
canvas.drawRoundRect(rect, borderRadius, borderRadius, borderPaint);
// 内容区
RectF rectIn = new RectF(rect.left + defaultContMargin, rect.top + defaultContMargin,
rect.right - defaultContMargin, rect.bottom - defaultContMargin);
borderPaint.setColor(Color.WHITE);
canvas.drawRoundRect(rectIn, borderRadius, borderRadius, borderPaint);
// 分割线
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 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);
}
}
完整代码下载
https://github.com/tianshaojie/Android-PasswordInputView
相关文章推荐
- 安卓/Android 模仿支付宝/微信 支付密码输入框的自定义View
- Android自定义View系列之Path绘制仿支付宝支付成功动画
- 自定义View——仿支付宝支付弹窗界面
- Android自定义View实现支付宝支付成功-极速get花式Path炫酷动画
- GridPasswordView 类似支付宝支付密码输入框
- 自定义View之自定义支付宝密码输入控件
- Android View进阶之实现仿支付宝手势密码自定义View
- Android - 使用自定义webview调用支付宝app支付
- 自定义view仿支付宝密码输入框
- Android一步一步剖析+实现仿支付宝手势密码自定义View
- kotlin实现的简单个人账户管理APP(三) 自定义View仿支付宝的密码输入框/密码相关逻辑
- Android自定义View仿支付宝输入六位密码功能_Android
- 自定义view之支付密码输入框
- 自定义view,仿微信、支付宝密码输入控件的源码实现
- Android自定义View仿支付宝输入六位密码功能
- [Android]仿支付宝自定义View密码框
- 自定义view-仿支付宝淘宝自定义密码
- 外界用户对支付宝登录密码认知度较低,只知道支付密码,因此设计如此
- Android自定义dialog实现支付宝支付成功样式
- js仿支付宝填写支付密码效果实现多方框输入密码