国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android 自定義View 密碼框?qū)嵗a

2019-12-12 06:14:53
字體:
供稿:網(wǎng)友

暴露您view中所有影響可見外觀的屬性或者行為。

•通過XML添加和設(shè)置樣式

•通過元素的屬性來控制其外觀和行為,支持和重要事件交流的事件監(jiān)聽器

詳細(xì)步驟見:Android 自定義View步驟

效果圖展示:

支持的樣式

可以通過XML定義影響外邊和行為的屬性如下

邊框圓角值,邊框顏色,分割線顏色,邊框?qū)挾龋艽a長度,密碼大小,密碼顏色

<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> 

同時(shí)支持原來EditText功能,可以獲得數(shù)據(jù)值,數(shù)字鍵盤設(shè)置等

繪制邏輯的主要代碼

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);// 內(nèi)容區(qū)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);}} 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 喜德县| 商都县| 英吉沙县| 将乐县| 东乌| 宝山区| 正宁县| 普安县| 卓资县| 司法| 杭锦后旗| 彭泽县| 永兴县| 桓仁| 通化县| 昌吉市| 砚山县| 平潭县| 中西区| 古蔺县| 堆龙德庆县| 金华市| 永登县| 太康县| 丰顺县| 麦盖提县| 邢台市| 扎赉特旗| 蛟河市| 怀宁县| 大渡口区| 旅游| 长武县| 宁化县| 岗巴县| 尉氏县| 施秉县| 德江县| 吉木乃县| 五家渠市| 三门县|