Android仿滴滴出行验证码输入框效果

1、前言

最近撸码忙成狗啊,果然从无到有的独立开发不是一般的累啊。。。。
最近公司项目中有一个类似滴滴出行填写验证码的弹框,下面是我撸出来的效果:

中间的那个输入密码的6个框框其实就是用shape画的背景,通过监听EditText获取焦点来改变背景,废话少说,直接上代码吧。

2、效果实现

代码内容比较简单,所以大家可以直接看代码

VerificationCodeInput.java

/**
 * @author hydCoder
 * @date 2017/9/22 14:39
 * @desc 输入验证码的自定义view
 * @email hyd_coder@163.com
 */

public class VerificationCodeInput extends LinearLayout implements TextWatcher, View.OnKeyListener{

private final static String TYPE_NUMBER = "number";
private final static String TYPE_TEXT = "text";
private final static String TYPE_PASSWORD = "password";
private final static String TYPE_PHONE = "phone";

private static final String   TAG           = "VerificationCodeInput";
private              int      box           = 4;
private              int      boxWidth      = 80;
private              int      boxHeight     = 80;
private              int      childHPadding = 14;
private              int      childVPadding = 14;
private              String   inputType     = TYPE_NUMBER;
private              Drawable boxBgFocus    = null;
private              Drawable boxBgNormal   = null;
private Listener listener;
private boolean        focus           = false;
private List<EditText> mEditTextList   = new ArrayList<>();
private int            currentPosition = 0;

public VerificationCodeInput(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.vericationCodeInput);
    box = a.getInt(R.styleable.vericationCodeInput_box, 4);

    childHPadding = (int) a.getDimension(R.styleable.vericationCodeInput_child_h_padding, 0);
    childVPadding = (int) a.getDimension(R.styleable.vericationCodeInput_child_v_padding, 0);
    boxBgFocus =  a.getDrawable(R.styleable.vericationCodeInput_box_bg_focus);
    boxBgNormal = a.getDrawable(R.styleable.vericationCodeInput_box_bg_normal);
    inputType = a.getString(R.styleable.vericationCodeInput_inputType);
    boxWidth = (int) a.getDimension(R.styleable.vericationCodeInput_child_width, boxWidth);
    boxHeight = (int) a.getDimension(R.styleable.vericationCodeInput_child_height, boxHeight);
    initViews();

}


@Ov
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值