Android 使用fast-verification實現驗證碼填寫功能的實例代碼
fast-verification
驗證碼的驗證環節現在是移動APP中不可缺少的一部分,直接使用EditText組件雖然方便但缺少了一些美感,使用fast-verification,讓實現驗證碼變得更簡單。
依賴到項目項目根gradle中添加
maven { url ’https://www.jitpack.io’ }
示例:
allprojects { repositories { ... maven { url ’https://www.jitpack.io’ } }}
在需要使用的module層級的gradle中添加
implementation ’com.github.sariki-L:fast-verification:1.1’
示例:
dependencies { ... implementation ’com.github.sariki-L:fast-verification:1.1’}
正式使用xml中添加VerificationLayout
<com.sariki.fastverification.VerificationLayout android:background='@android:color/transparent' android: android:layout_width='match_parent' android:layout_height='match_parent'/>
初始化
verification = findViewById(R.id.verification); verification.init(this, VerificationType.LENGTH_LONG);
變量名 對應驗證碼長度 VerificationType.LENGTH_LONG 6位 VerificationType.LENGTH_SHORT 4位
驗證碼輸入完成時的回調
verification.setEndListener(new VerificationTypeListener() { @Override public void onFinish(String result) { if (!result.equals(**需校對內容**)){ verification.setErrType(); }else{ ... } } });
在setEndListener中設置監聽,重寫onFinish方法處理輸入完成后的狀態。setErrType為調用默認錯誤處理。
設置參數
如果對默認驗證碼框背景不滿意,可以在代碼中對部分參數進行更改
需寫在init調用前
設置驗證碼框背景
verification.setDrawBackground();
設置驗證碼文字大小
verification.setDrawSize();
設置驗證碼文字顏色
verification.setDrawColor();
項目地址:github
總結
到此這篇關于Android 使用fast-verification實現驗證碼填寫功能的文章就介紹到這了,更多相關Android 使用fast-verification實現驗證碼填寫功能內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章: