Android自定義控件實現(xiàn)短信驗證碼自動填充
VerifyCodeView
VerifyCodeView是一個用于輸入驗證碼的Android自定義控件,它支持數(shù)字類型的驗證碼,支持自定義外觀,并且支持短信驗證碼自動填充。
項目地址:VerifyCodeView


在項目中引入VerifyCodeView
Gradle
dependencies {
compile 'com.github.gongw:verifycodeview:1.0.2'
}
Maven
<dependency> <groupId>com.github.gongw</groupId> <artifactId>verifycodeview</artifactId> <version>1.0.2</version> <type>pom</type> </dependency>
支持的自定義屬性
- vcTextCount - 驗證碼長度
- vcTextColor - 驗證碼字體顏色
- vcTextSize - 驗證碼字體大小,單位sp
- vcTextFont - 驗證碼字體樣式文件路徑(assets中的路徑)
- vcDividerWidth - 每個驗證碼之間的間隔距離,單位dp
- vcWrapper - 包裹驗證碼的外觀樣式
- vcWrapperStrokeWidth - 包裹驗證碼的外觀的線條寬度,單位dp
- vcWrapperColor - 包裹驗證碼的外觀顏色
- vcNextWrapperColor - 包裹將要被填充的驗證碼的外觀顏色
使用示例
xml
<com.github.gongw.VerifyCodeView android:layout_width="240dp" android:layout_height="50dp" android:layout_marginTop="42dp" app:vcTextColor="#b63b21" app:vcTextCount="4" app:vcTextSize="36sp" app:vcDividerWidth="8dp" app:vcWrapper="centerLine" app:vcWrapperColor="#313335" app:vcNextWrapperColor="#b63b21" app:vcWrapperStrokeWidth="2dp" />
java
verifycodeView.setOnAllFilledListener(new VerifyCodeView.OnAllFilledListener() {
@Override
public void onAllFilled(String text) {
Toast.makeText(MainActivity.this, "filled by "+text, Toast.LENGTH_SHORT).show();
}
});
自定義外觀
verifycodeView.setVcWrapper(new VerifyCodeWrapper() {
@Override
public boolean isCovered() {
//whether the wrapper and verify code display together
return false;
}
@Override
public void drawWrapper(Canvas canvas, Paint paint, RectF rectF, RectF textRectF) {
//draw your own wrapper
canvas.drawLine(textRectF.left - textRectF.width()/2, rectF.height()/2, textRectF.right + textRectF.width() / 2, rectF.height()/2, paint);
}
});
短信驗證碼自動填充
SmsVerifyCodeFilter filter = new SmsVerifyCodeFilter();
filter.setSmsSenderStart("1096");
filter.setSmsSenderContains("5225");
filter.setSmsBodyStart("驗證短信:");
filter.setSmsBodyContains("驗證碼");
filter.setVerifyCodeCount(verifyCodeView.getVcTextCount());
verifyCodeView.startListen(filter);
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
mui.init()與mui.plusReady()區(qū)別和關(guān)系
給大家分享一下在使用MUI進行APP開發(fā)的時候,mui.init()與mui.plusReady()區(qū)別以及使用上不同之處。2017-11-11
android編程實現(xiàn)添加文本內(nèi)容到sqlite表中的方法
這篇文章主要介紹了android編程實現(xiàn)添加文本內(nèi)容到sqlite表中的方法,結(jié)合實例較為詳細的分析了Android針對txt文本文件的讀取及SQL數(shù)據(jù)庫操作的相關(guān)技巧,需要的朋友可以參考下2015-11-11
Android模仿實現(xiàn)微博詳情頁滑動固定頂部欄的效果實例
這篇文章主要給大家介紹了關(guān)于利用Android模仿實現(xiàn)微博詳情頁滑動固定頂部欄效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11
Flutter學(xué)習(xí)之實現(xiàn)自定義themes詳解
一般情況下我們在flutter中搭建的app基本上都是用的是MaterialApp這種設(shè)計模式,MaterialApp中為我們接下來使用的按鈕,菜單等提供了統(tǒng)一的樣式,那么這種樣式能不能進行修改或者自定義呢?答案是肯定的,一起來看看吧2023-03-03
Android 狀態(tài)欄的設(shè)置適配問題詳解
這篇文章主要介紹了Android 狀態(tài)欄的設(shè)置適配問題詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06

