android方块密码输入框,Android仿微信/支付宝的方块密码输入框

在用到支付类或者验证类app时,都有一个简密的输入框。百度了下有个不错的帖子点击打开链接

不过自己也写了个简单的类似的。不废话了。没图说个席八。

0818b9ca8b590ca3270a3433284dd417.png

懒得运行,直接截layout.xml的效果图先。

布局文件

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#ffffff"

android:paddingBottom="20dp"

android:paddingTop="30dp" >

android:id="@+id/txtTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:text="请输入验证码"

android:textStyle="bold"

android:textSize="22sp" />

android:id="@+id/layout"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/txtTitle"

android:layout_centerHorizontal="true"

android:layout_marginTop="10dp"

android:orientation="horizontal" >

android:id="@+id/t1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/i1"

android:gravity="center"

android:inputType="number"

android:lines="1"

android:maxLines="1" />

android:id="@+id/t2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/i1"

android:gravity="center"

android:inputType="number"

android:lines="1"

android:maxLines="1" />

android:id="@+id/t3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/i1"

android:gravity="center"

android:inputType="number"

android:lines="1"

android:maxLines="1" />

android:id="@+id/t4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/i2"

android:gravity="center"

android:inputType="number"

android:lines="1"

android:maxLines="1" />

android:id="@+id/editHide"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/layout"

android:layout_alignLeft="@+id/layout"

android:layout_alignRight="@+id/layout"

android:layout_alignTop="@+id/layout"

android:layout_weight="1"

android:background="#00000000"

android:cursorVisible="false"

android:ems="10"

android:inputType="number"

android:maxLength="4"

android:textColor="#00000000" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/layout"

android:layout_centerHorizontal="true"

android:layout_marginTop="20dp" >

android:id="@+id/verifycode_ok"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#fa8d70"

android:layout_marginRight="30dp"

android:textColor="#ffffff"

android:text="确定" />

android:id="@+id/verifycode_cancel"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="30dp"

android:background="@color/index_time_but"

android:textColor="#ffffff"

android:text="取消" />

代码:

import android.app.Activity;

import android.os.Bundle;

import android.text.Editable;

import android.text.TextWatcher;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity extends Activity {

TextView t1, t2, t3, t4, et;

String key = "";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.verifycode);

t1 = (TextView) findViewById(R.id.t1);

t2 = (TextView) findViewById(R.id.t2);

t3 = (TextView) findViewById(R.id.t3);

t4 = (TextView) findViewById(R.id.t4);

et = (EditText) findViewById(R.id.editText1);

et.addTextChangedListener(tw);

}

void setKey() {

char[] arr = key.toCharArray();

t1.setText("");

t2.setText("");

t3.setText("");

t4.setText("");

for (int i = 0; i < arr.length; i++) {

if (i == 0) {

t1.setText(String.valueOf(arr[0]));

} else if (i == 1) {

t2.setText(String.valueOf(arr[1]));

} else if (i == 2) {

t3.setText(String.valueOf(arr[2]));

} else if (i == 3) {

t4.setText(String.valueOf(arr[3]));

}

}

}

TextWatcher tw = new TextWatcher() {

@Override

public void onTextChanged(CharSequence s, int start, int before,

int count) {

}

@Override

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

}

@Override

public void afterTextChanged(Editable s) {

key = s.toString();

setKey();

}

};

}

好哒。就这样了。运行就有效果了。没有什么自定义,没有什么第三方。

当然。如果你要弹窗形式的话,也一样,加下面的就能弹窗了

final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

dialog.show();

dialog.getWindow().setContentView(R.layout.verifycode);t1 = (TextView) dialog.findViewById(R.id.t1);

t2 = (TextView) dialog.findViewById(R.id.t2);

t3 = (TextView) dialog.findViewById(R.id.t3);

t4 = (TextView) dialog.findViewById(R.id.t4); 后期有时间再补上项目DOME。下班。走人

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/294034.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

童鞋,[HttpClient发送文件的技术实践]请查收

昨天有童鞋在群里面问&#xff1a;怎么使用HttpClient发送文件&#xff1f;01荒腔走板之前我写了一个《ABP小试牛刀之上传文件》&#xff0c;主要体现的是服务端&#xff0c;上传文件的动作是由前端小姐姐完成的&#xff0c; 我还真没有用HttpClient编程方式发送过文件。不过Ht…

Android之Camera介绍

Android Camera 使用小结 Android手机关于Camera的使用&#xff0c;一是拍照&#xff0c;二是摄像&#xff0c;由于Android提供了强大的组件功能&#xff0c;为此对于在Android手机系统上进行Camera的开发&#xff0c;我们可以使用两类方法&#xff1a;一是借助Intent和MediaSt…

elasticsearch2.2之javaApi

2019独角兽企业重金招聘Python工程师标准>>> 前言&#xff1a;elasticsearch虽然自带rest接口&#xff0c;但是在真正使用过程中可能更多的是通过不同编程语言的客户端进行交互。 因为代码里有或多或少的注释&#xff0c;所以直接贴代码&#xff1a; package elasti…

My SQL 学习笔记二

本文主要记录这两天遇到的问题&#xff1a; 1.sql脚本文件存在自己的目录下&#xff0c;例如在F盘&#xff0c;通过命令&#xff1a;mysql> source F:/filename.sql 会弹出Failed to open file "F:/filename.sql" error:2 错误 这个错误一般是Mysql没有权限访问文…

《程序员的职业素养》读书笔记

书籍地址&#xff1a;http://book.douban.com/subject/11614538/ 一句话点评该书&#xff1a;Bob大叔的职业生涯经验总结&#xff0c;现身说法&#xff0c;可信可敬&#xff01; &#xff08;一&#xff09;专业主义 &#xff08;1&#xff09;“专业主义”就意味着担当责…

html 转义反斜杠字符串,JS中处理单个反斜杠(即转义字符的处理)

问题来源&#xff1a;在表单的标签中对输入的字符串进行大写转换。一不小心输入了反斜杠 \如下图所示&#xff1a;输入 chn\ 的时候&#xff0c;在 IE8 下弹出一个js错误。(在实际的项目的表单元素中遇到了&#xff0c;单独这样拿出来测试的时候又不弹出错误。也很是焦灼)索…

Android之SurfaceView简介(一)

1. SurfaceView介绍 通常情况程序的View和用户响应都是在同一个线程中处理的&#xff0c;这也是为什么处理长时间事件&#xff08;例如访问网络&#xff09;需要放到另外的线程中去&#xff08;防止阻塞当前UI线程的操作和绘制&#xff09;。但是在其他线程中却不能修改UI元素&…

C# 值得永久收藏的WPF项目实战(经典)

01—简介之前也写过好多篇CM框架相关的项目实战文章&#xff0c;比如&#xff1a;C# WPF框架Caliburn.Micro快速搭建C# WPF框架Caliburn.Micro入门实例1C# WPF MVVM项目实战(进阶①)C# WPF MVVM项目实战(进阶②)C# WPF MVVM模式下在主窗体显示子窗体并获取结果C# WPF Caliburn.…

InfoQ十周年:不忘初心,继续前行

我们都知道&#xff1a;软件正在改变世界&#xff0c;也已经看到了在加快这种变化时&#xff0c;于软件世界中我们的影响力。在这种热情下&#xff0c;10年前我们带着一些不寻常的信念与情怀创建了InfoQ&#xff1a;\\\\t我们相信&#xff1a;这个社区需要的内容是开发者所撰写…

eclipse_中的注释_快捷键

eclipse 中的注释 快捷键 把要注释的代码选中&#xff0c;按CtrlShift/ /* */ 形式的 ctrl/ //形式的 取消代码注释&#xff1a; 把要注释的代码选中&#xff0c;按CtrlShift\ /* */ 形式的 ctrl/ //形式的 (1)CtrlSpace 说明:内容助理。提供对方法,变量,参数,j…

html自动填充高度,html元素如何仅使用css填充剩余屏幕高度的100%?

html元素如何仅使用css填充剩余屏幕高度的100&#xff05;&#xff1f;我有一个标题元素和一个内容元素&#xff1a;#header#content我希望标题具有固定的高度&#xff0c;并且内容可以填满屏幕上可用的所有剩余高度&#xff0c;使用overflow-y: scroll;。这可能没有Javascript…

Android之bitmap压缩的几种方法的解读

转载&#xff1a;http://blog.csdn.net/chzphoenix/article/details/30242315?utm_sourcetuicool&utm_mediumreferral 最近在研究微信的sdk&#xff0c;在缩略图这遇到了一点问题。 微信的缩略图要求是不大于32k&#xff0c;这就需要对我的图片进行压缩。试了几种方法&a…

如何通过 C# kill 指定进程?

咨询区 robr我用代码动态的打开了一个 IE 进程&#xff0c;参考如下代码&#xff1a;static void Main(string[] args){ProcessStartInfo startInfo new ProcessStartInfo("iexplore.exe");startInfo.WindowStyle ProcessWindowStyle.Hidden;startInfo.Arguments …

[转]面向接口编程详解(一)——思想基础

我想&#xff0c;对于各位使用面向对象编程语言的程序员来说&#xff0c;“接口”这个名词一定不陌生&#xff0c;但是不知各位有没有这样的疑惑&#xff1a;接口有什么用途&#xff1f;它和抽象类有什么区别&#xff1f;能不能用抽象类代替接口呢&#xff1f;而且&#xff0c;…

bootstrap模态框

bootsrtap模态框不可叠加使用&#xff0c;点击提交时需要确认&#xff0c;暂时未解决转载于:https://www.cnblogs.com/witchgogogo/p/5550338.html

Oracle 在 多个Virtualbox 虚拟机间 跨不同物理宿主机进行通信

因为单位网络管理的原因&#xff0c;不太方便使用 Virtualbox 的Bridge Adapter 模式&#xff0c;故此欲采用NAT模式&#xff0c;不对外不暴露虚拟机IP。 但是此时会有一个问题&#xff1a;采用NAT模式后&#xff0c;在通常情况下&#xff0c; 从外面看&#xff0c;或者从物理机…

Android之解决在非Activity中使用startActivity

今天遇到一个问题就是&#xff0c;如何在非activity里面使用startActivity(); 解决办法如下、 需要我们有context intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);

亚马逊 html代码转换,亚马逊七种产品描述常用HTML代码,文字颜色代码让Listing更出彩...

排版风格和排版水平对于亚马逊Listing的运营至关重要。虽说亚马逊以产品为王&#xff0c;但如果消费者打开的是一篇毫无美感的排版&#xff0c;视觉体验不舒服&#xff0c;获取不到吸引他的卖点&#xff0c;转化率将大大降低&#xff01;没使用HTML代码的卖家&#xff0c;产品描…