Git Product home page Git Product logo

androidverificationcode's Introduction

类滴滴验证码输入框,长这样:

emmmmmm,好像截了iOS的图,不要在意这些细节。

实现思路

笔者这里决定继承RelativeLayout来实现自定义验证码的功能。显示验证码可以使用几个TextView,这里需要将TextView统一管理,所以还需要一个TextView数组。有光标,那自然而然的就想到了EditText,可以使用一个透明背景的EditText。几个验证码可以使用TextView以一定的规则进行排列,通过监听EditText的输入,拦截到输入字符,并将字符传递给TextView数组,并将EditText置为空,同时重设TextView选中状态,移动EditText光标。笔者这里采用给EditText设置paddingLeft的方式来实现光标的移动,当然,需要经过一些计算。OK,大概思路就是这样了,具体的代码我们继续看下面的。

使用:

<com.xylitolz.androidverificationcode.view.VerificationCodeView
        android:id="@+id/view_verification"
		android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        app:vcv_code_size="16sp"
        app:vcv_code_bg_focus="@drawable/bg_text_focused"
        app:vcv_code_bg_normal="@drawable/bg_text_normal"
        app:vcv_code_color="@color/text_border_focused"
        app:vcv_code_number="4"
        app:vcv_code_width="50dp"/>

效果:

相关博客地址:Android自定义View-仿滴滴自定义验证码输入框

androidverificationcode's People

Contributors

riceeater avatar chinaaj avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.