溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Android中怎么通過自定義控件實現(xiàn)短信驗證碼自動填充

發(fā)布時間:2021-08-07 11:42:13 來源:億速云 閱讀:178 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關(guān)Android中怎么通過自定義控件實現(xiàn)短信驗證碼自動填充,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

VerifyCodeView

VerifyCodeView是一個用于輸入驗證碼的Android自定義控件,它支持?jǐn)?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)容,你們對Android中怎么通過自定義控件實現(xiàn)短信驗證碼自動填充有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI