這篇文章主要為大家展示了“Android如何自定義驗證碼輸入框”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Android如何自定義驗證碼輸入框”這篇文章吧。
需求
1、能自定義輸入框個數(shù)和樣式
2、支持長按粘貼或剪切板內(nèi)容自動填充(粘貼連續(xù)性)
其中第2點是最為重要的,正是其他人沒有這點,逼得自己弄一個
原理
大致是Edittext + n* TextView,然后設置edittext字體跟背景顏色都為透明,隱藏光標
Edittext:監(jiān)聽edittext每次輸入一個字符就賦值到對應的TextView上,然后在清空自己
下劃線:在TextView下面添加View
光標:這里的每個TextView的焦點光標其實對View設置了ValueAnimator
粘貼:粘貼彈窗是自定義的PopupWindow
源碼有詳細注釋,這里就不一一說明
Github
https://github.com/WShaobin/VerificationCodeInputView
Gradle
Step 1. Add it in your root build.gradle at the end of repositories:
allprojects { repositories { ... maven { url 'https://jitpack.io' } }}
Step 2. Add the dependency:
dependencies { implementation 'com.github.WShaobin:VerificationCodeInputView:1.0.2'}
How to use
In layout
<com.wynsbin.vciv.VerificationCodeInputView android:id="@+id/vciv_code" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="48dp" android:gravity="center" android:orientation="horizontal" app:vciv_et_background="@android:color/white" app:vciv_et_foucs_background="@android:color/holo_orange_dark" app:vciv_et_cursor_color="@color/colorPrimary" app:vciv_et_height="58dp" app:vciv_et_inputType="number" app:vciv_et_number="6" app:vciv_et_text_color="@android:color/black" app:vciv_et_text_size="18sp" app:vciv_et_underline_default_color="@android:color/holo_green_dark" app:vciv_et_underline_focus_color="@android:color/holo_blue_bright" app:vciv_et_underline_height="2dp" app:vciv_et_underline_show="true" app:vciv_et_width="58dp" />
In Java Code
VerificationCodeInputView view = findViewById(R.id.vciv_code);view.setOnInputListener(new VerificationCodeInputView.OnInputListener() { @Override public void onComplete(String code) { Toast.makeText(MainActivity.this, code, Toast.LENGTH_SHORT).show(); } @Override public void onInput() { }});//清除驗證碼view.clearCode();
Attributes
VCInputType
輸入框背景色支持類型
1、@drawable/xxx
2、@color/xxx
3、#xxxxxx
以上是“Android如何自定義驗證碼輸入框”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當前名稱:Android如何自定義驗證碼輸入框-創(chuàng)新互聯(lián)
鏈接分享:http://jinyejixie.com/article24/jsece.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、軟件開發(fā)、移動網(wǎng)站建設、網(wǎng)站設計公司、網(wǎng)站導航、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容