欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2019年12月25日 17:22:55   作者:gogo_wei  
這篇文章主要為大家詳細(xì)介紹了Android自定義控件實(shí)現(xiàn)短信驗(yàn)證碼自動填充,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

VerifyCodeView

VerifyCodeView是一個用于輸入驗(yàn)證碼的Android自定義控件,它支持?jǐn)?shù)字類型的驗(yàn)證碼,支持自定義外觀,并且支持短信驗(yàn)證碼自動填充。

項(xiàng)目地址:VerifyCodeView

在項(xiàng)目中引入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 - 驗(yàn)證碼長度
  • vcTextColor - 驗(yàn)證碼字體顏色
  • vcTextSize - 驗(yàn)證碼字體大小,單位sp
  • vcTextFont - 驗(yàn)證碼字體樣式文件路徑(assets中的路徑)
  • vcDividerWidth - 每個驗(yàn)證碼之間的間隔距離,單位dp
  • vcWrapper - 包裹驗(yàn)證碼的外觀樣式
  • vcWrapperStrokeWidth - 包裹驗(yàn)證碼的外觀的線條寬度,單位dp
  • vcWrapperColor - 包裹驗(yàn)證碼的外觀顏色
  • vcNextWrapperColor - 包裹將要被填充的驗(yàn)證碼的外觀顏色

使用示例

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);
   }
  });

短信驗(yàn)證碼自動填充

SmsVerifyCodeFilter filter = new SmsVerifyCodeFilter();
filter.setSmsSenderStart("1096");
filter.setSmsSenderContains("5225");
filter.setSmsBodyStart("驗(yàn)證短信:");
filter.setSmsBodyContains("驗(yàn)證碼");
filter.setVerifyCodeCount(verifyCodeView.getVcTextCount());
verifyCodeView.startListen(filter);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論