雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

Android

當(dāng)前位置:主頁 > 軟件編程 > Android >

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

來源:本站原創(chuàng)|時間:2020-01-10|欄目:Android|點擊:

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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:Android實現(xiàn)原生鎖屏頁面音樂控制

欄    目:Android

下一篇:Android實現(xiàn)音樂播放器鎖屏頁

本文標(biāo)題:Android自定義控件實現(xiàn)短信驗證碼自動填充

本文地址:http://www.jygsgssxh.com/a1/Android/8979.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有