星空网 > 软件开发 > 操作系统

(转)[原] Android 自定义View 密码框 例子

遵从准则

暴露您view中所有影响可见外观的属性或者行为。

  • 通过
  • 通过元素的属性来控制其外观和行为,支持和重要事件交流的事件**

详细步骤见:Android 自定义View步骤

样子

(转)[原] Android 自定义View 密码框 例子images/loading.gif' data-original="http://images.cnitblog.com/blog/275810/201406/201603547239542.jpg" width="292" height="484" border="0" />

支持的样式

可以通过

边框圆角值,边框颜色,分割线颜色,边框宽度,密码长度,密码大小,密码颜色

<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

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

卖家们必学的向客户宣布涨价技巧:https://www.ikjzd.com/articles/124916
玩爆亚马逊广告,学会这招就够啦!:https://www.ikjzd.com/articles/124917
新冠疫情下,中西部外贸逆势高增长,凭什么?:https://www.ikjzd.com/articles/124918
TikTok 版 DOU+ 已进入内测?又可以造作了①:https://www.ikjzd.com/articles/124927
跨境电商那么多为什么选择shopee?六大优势讲解分析:https://www.ikjzd.com/articles/124929
为什么你的shopee店铺出单难?新手如何快速出单,掌握这六点:https://www.ikjzd.com/articles/124939
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流