跟选择银行卡界面类似,也是用一个PopupWindow,不过输入密码界面是一个自定义view,当输入六位密码完成后用回调在Activity中获取到输入的密码并以Toast显示密码。效果图如下:

自定义view布局效果图及代码如下:

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@drawable/bg_pop_window"

android:orientation="vertical">

android:id="@+id/ll_main_password"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:background="#fff"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="50dp">

android:id="@+id/iv_pay_back"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerVertical="true"

android:layout_marginLeft="10dp"

android:background="@drawable/back_white"/>

android:id="@+id/tv_pay_title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_marginLeft="15dp"

android:layout_marginTop="15dp"

android:text="标题"

android:textColor="#333"

android:textSize="18dp"/>

android:layout_width="match_parent"

android:layout_height="0.5dp"

android:background="#e5e5e5"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginLeft="20dp"

android:layout_marginRight="20dp"

android:layout_marginTop="20dp"

android:background="@drawable/shape_input_area"

android:orientation="horizontal">

android:id="@+id/tv_pass1"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:inputType="numberPassword"

android:paddingBottom="5dp"

android:paddingTop="5dp"

android:textSize="32sp"/>

android:layout_width="1dp"

android:layout_height="match_parent"

android:background="#e5e5e5"/>

android:id="@+id/tv_pass2"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:inputType="numberPassword"

android:paddingBottom="5dp"

android:paddingTop="5dp"

android:textSize="32sp"/>

android:layout_width="1dp"

android:layout_height="match_parent"

android:background="#e5e5e5"/>

android:id="@+id/tv_pass3"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:inputType="numberPassword"

android:paddingBottom="5dp"

android:paddingTop="5dp"

android:textSize="32sp"/>

android:layout_width="1dp"

android:layout_height="match_parent"

android:background="#e5e5e5"/>

android:id="@+id/tv_pass4"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:inputType="numberPassword"

android:paddingBottom="5dp"

android:paddingTop="5dp"

android:textSize="32sp"/>

android:layout_width="1dp"

android:layout_height="match_parent"

android:background="#e5e5e5"/>

android:id="@+id/tv_pass5"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:inputType="numberPassword"

android:paddingBottom="5dp"

android:paddingTop="5dp"

android:textSize="32sp"/>

android:layout_width="1dp"

android:layout_height="match_parent"

android:background="#e5e5e5"/>

android:id="@+id/tv_pass6"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:gravity="center"

android:inputType="numberPassword"

android:paddingBottom="5dp"

android:paddingTop="5dp"

android:textSize="32sp"/>

android:id="@+id/tv_pay_forgetPwd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="right"

android:layout_margin="15dp"

android:text="忘记密码?"

android:textColor="#354EEF"/>

android:id="@+id/gv_keybord"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/ll_main_password"

android:layout_marginTop="30dp"

android:horizontalSpacing="0.5dp"

android:background="#8E8E8E"

android:numColumns="3"

android:verticalSpacing="0.5dp"/>

java代码

/**

* Created by zhpan on 2016/9/25.

*/

public class PayView extends RelativeLayout{

private MainActivity mContext;

private String mStringPassword; //输入的密码

private TextView[] mTextViewPsw; // 用数组保存6个TextView

private GridView mGridView; //支付键盘布局

private ArrayList> valueList;

private ImageView mImageViewCancel;

private TextView mTextViewForgetPsw;

private int currentIndex = -1;// 用于记录当前输入密码格位置

private View mView;

private TextView mTextViewTitle;

private TextView mTextViewDel;

public PayView(Context context) {

super(context, null);

}

public PayView(Context context, AttributeSet attrs) {

super(context, attrs);

mContext = (MainActivity) context;

mView = View.inflate(context, R.layout.pay_view, null);

valueList = new ArrayList<>();

mTextViewPsw = new TextView[6];

mImageViewCancel = (ImageView) mView.findViewById(R.id.iv_pay_back);

mTextViewPsw[0] = (TextView) mView.findViewById(R.id.tv_pass1);

mTextViewPsw[1] = (TextView) mView.findViewById(R.id.tv_pass2);

mTextViewPsw[2] = (TextView) mView.findViewById(R.id.tv_pass3);

mTextViewPsw[3] = (TextView) mView.findViewById(R.id.tv_pass4);

mTextViewPsw[4] = (TextView) mView.findViewById(R.id.tv_pass5);

mTextViewPsw[5] = (TextView) mView.findViewById(R.id.tv_pass6);

mGridView = (GridView) mView.findViewById(R.id.gv_keybord);

mTextViewTitle = (TextView) mView.findViewById(R.id.tv_pay_title);

mTextViewForgetPsw = (TextView) mView.findViewById(R.id.tv_pay_forgetPwd);

setView();

addView(mView); //必须要,不然不显示控件

}

// 初始化按钮上应该显示的数字

private void setView() {

for (int i = 1; i < 13; i++) {

Map map = new HashMap<>();

if (i < 10) {

map.put("name", String.valueOf(i));

} else if (i == 10) {

map.put("name", "");

} else if (i == 11) {

map.put("name", String.valueOf(0));

} else if (i == 12) {

map.put("name", "

}

valueList.add(map);

}

mGridView.setAdapter(adapter);

}

/**

* 设置监听方法,在第6位输入完后触发

*/

public void setOnFinishInput(final OnPasswordInputFinish pass) {

mTextViewPsw[5].addTextChangedListener(new TextWatcher() {

@Override

public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override

public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override

public void afterTextChanged(Editable s) {

if (s.toString().length() == 1) {

mStringPassword = ""; //每次触发都要将mStringPassword置空再重新获取,避免由于输入删除再输入造成混乱

for (int i = 0; i < 6; i++) {

mStringPassword += mTextViewPsw[i].getText().toString().trim();

}

pass.inputFinish();//接口中要实现的方法,完成密码输入完成后的响应逻辑

}

}

});

}

/**

* 获取输入的密码

*/

public String getPassword() {

return mStringPassword;

}

/**

* 返回取消支付的ImageView

*/

public ImageView getCancel() {

return mImageViewCancel;

}

/**

* 返回忘记密码的TextView

*/

public TextView getForgetPsw() {

return mTextViewForgetPsw;

}

/**

* 返回标题的TextView

*/

public TextView getTitle() {

return mTextViewTitle;

}

// GridView的适配器

BaseAdapter adapter = new BaseAdapter() {

@Override

public int getCount() {

return valueList.size();

}

@Override

public Object getItem(int position) {

return valueList.get(position);

}

@Override

public long getItemId(int position) {

return position;

}

@Override

public View getView(final int position, View convertView, ViewGroup parent) {

ViewHolder holder;

if (convertView == null) {

convertView = View.inflate(mContext, R.layout.item_pay_gride, null);

holder = new ViewHolder();

holder.btnKey = (TextView) convertView.findViewById(R.id.btn_keys);

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();

}

holder.btnKey.setText(valueList.get(position).get("name"));

if (position == 9) {

holder.btnKey.setBackgroundResource(R.drawable.selector_key_del);

}

if (position == 11) {

mTextViewDel = holder.btnKey;

holder.btnKey.setBackgroundResource(R.drawable.selector_key_del);

}

holder.btnKey.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

if (position < 11 && currentIndex != 9&&position!=9) { //点击0-9按钮

if (currentIndex >= -1 && currentIndex < 5) { //判断输入位置

mTextViewPsw[++currentIndex].setText(valueList.get(position).get("name"));

}

} else {

if (position == 11) { //点击退格键

if (currentIndex - 1 >= -1) { // 判断是否删除完毕

mTextViewPsw[currentIndex--].setText("");

}

}

if(position==9){

}

}

}

});

return convertView;

}

};

static class ViewHolder {

public TextView btnKey;

}

}

PopupWindow中直接使用该控件

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/pv_pop_win"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

MainActivity中显示PupupWindow

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private TextView mTextView;

private PopupWindow mPopupWindow;

private View popView;

private PayView mPayView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initView();

setListener();

}

private void initView() {

mTextView = (TextView) findViewById(R.id.tv_main_pay);

}

private void setListener() {

mTextView.setOnClickListener(this);

}

// 显示弹窗

public void showPopupWindow() {

// 初始化弹窗

popView = View.inflate(this, R.layout.pop_window, null);

mPopupWindow = new PopupWindow(popView, ViewGroup.LayoutParams.MATCH_PARENT,

ViewGroup.LayoutParams.MATCH_PARENT);

mPayView = (PayView) popView.findViewById(R.id.pv_pop_win);

mPayView.getTitle().setText("选择到账银行卡");

// 设置动画

mPopupWindow.setAnimationStyle(R.style.popwin_anim_style);

mPopupWindow.showAsDropDown(findViewById(R.id.ll_main), 0, 0);

mPopupWindow.setOutsideTouchable(true);

mPayView.setOnFinishInput(new OnPasswordInputFinish() {

@Override

public void inputFinish() {

Toast.makeText(MainActivity.this, mPayView.getPassword(), Toast.LENGTH_SHORT).show();

}

});

mPayView.getCancel().setOnClickListener(this);

mPayView.getForgetPsw().setOnClickListener(this);

}

@Override

public void onClick(View v) {

switch (v.getId()) {

case R.id.tv_main_pay:

showPopupWindow();

break;

case R.id.iv_pay_back:

mPopupWindow.dismiss();

break;

case R.id.tv_pay_forgetPwd:

Toast.makeText(MainActivity.this,"忘记密码",Toast.LENGTH_SHORT).show();

break;

}

}

}

以上所述是小编给大家介绍的Android自定义View仿支付宝输入六位密码功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

android wear支付宝6,Android自定义View仿支付宝输入六位密码功能相关推荐

  1. Android仿支付宝UI功能开发,Android 自定义view仿支付宝咻一咻功能

    支付宝上有一个咻一咻的功能,就是点击图片后四周有水波纹的这种效果,今天也写一个类似的功能. 效果如下所示: 思路: 就是几个圆的半径不断在变大,这个可以使用动画缩放实现,还有透明动画 还有就是这是好几 ...

  2. android自定义表盘部件,Android自定义view仿支付宝芝麻信用表盘

    演示效果 实现步骤: 1.画不同宽度和半径的内外圆弧 2.通过循环旋转canvas,在固定位置绘制短线刻度,长线刻度,刻度文字 3.绘制view中心几个文本,并调整位置 4.实时更新当前旋转角度刷新小 ...

  3. android 自定义view仿支付宝写五褔及播放

    本文记录一下实现仿支付宝写五褔及回放的过程. 先看效果如下,没有找到相关的背景图,只能以田字格当作背景. 整个过程分为两部分,一部分是写字,一部份是回放. 该过程主要使用了path和pathmeasu ...

  4. android记账本折线图_Android自定义View - 仿支付宝月账单折线图

    前言 支付宝有个查看月账单的功能,最近一直在学习自定义View,于是就尝试着自己实现了一个类似的折线图. 下面是支付宝消费分析功能截图和自己实现的折线效果截图: 支付宝消费分析折线图.jpg 效果1. ...

  5. Android 仿芝麻信用进度条,自定义View仿支付宝芝麻信用分仪表盘效果

    image 前言 灵感来自几天前看到一位作者的仿芝麻信用自定义View的文章很不错,所以我换了一种方式来进行实现,写了旧版和新版芝麻信用分仪表盘的效果. 截图 这是我做的效果,还是有点差距的,嘿嘿. ...

  6. kotlin实现的简单个人账户管理APP(三) 自定义View仿支付宝的密码输入框/密码相关逻辑

    转载请注明出处:http://blog.csdn.net/a512337862/article/details/78874322 前言 1.本篇博客相关的项目介绍请参考基于kotlin实现的简单个人账 ...

  7. 自定义View仿支付宝芝麻信用分仪表盘效果

    前言 灵感来自几天前看到一位作者的仿芝麻信用自定义View的文章很不错,所以我换了一种方式来进行实现,写了旧版和新版芝麻信用分仪表盘的效果. Github地址: https://github.com/ ...

  8. android 自定义中文加盘,Android自定义View仿支付宝芝麻信用分仪表盘

    先看下iOS的芝麻信用分截图 这是我做的效果,还是有点差距的 支付宝9.9版本芝麻信用分的实现 首先初始化各种画笔,默认的size,padding,小圆点. (因为实在找不到原版芝麻信用的带点模糊效果 ...

  9. Android特效专辑(十二)——仿支付宝咻一咻功能实现波纹扩散特效,精细小巧的View...

    Android特效专辑(十二)--仿支付宝咻一咻功能实现波纹扩散特效,精细小巧的View 先来看看这个效果 这是我的在Only上添加的效果,说实话,Only现在都还只是半成品,台面都上不了,怪自己技术 ...

最新文章

  1. Rxjava之操作符distinct和elementAt
  2. sudo运行程序遇到的问题
  3. clang 搭建和编译boost 和zero ICE库 (Ubuntu10 64)
  4. 计算机组成原理试卷五套,计算机组成原理(五套试题)
  5. php+数学计算公式,PHP数学计算函数总结
  6. mac 10.11 安装mysql5.7.10压缩版
  7. 【RK3399Pro学习笔记】十六、ROS中的常用可视化工具
  8. 驱动框架3——在内核中添加或去除某个驱动
  9. 【BZOJ4602】齿轮,带权并查集
  10. 图像的频率谱和功率谱代表什么_使用 FastAI 和即时频率变换进行音频分类
  11. c++ using 前置声明_详解C++ 前置声明
  12. ON1 Effects 2022 for mac(ps调色滤镜库)支持m1
  13. requestFullscreen()事件全屏不好使怎么解决
  14. PPT自动添加进度条与页码
  15. [转]用python来开发webgame服务端(5)
  16. TCP接收到重叠数据(overlap)后的行为解析-附带一个有关Delay ACK和超时重传的优化
  17. 网络可视化工具netron
  18. 为什么大型高难度工程的首选支模架是盘扣架?
  19. 为什么使用高匿代理IP会被检测出许多问题,都有哪些问题呢?
  20. 手淘双十一性能优化项目揭秘

热门文章

  1. ubuntu18.04 安装英伟达显卡驱动
  2. 时尚的不仅仅是它们的服装,还有它们的网站设计
  3. ios7再现大bug:iPhone大面积“激活出错”
  4. android 无法隐藏键盘,我无法在Android上隐藏虚拟键盘
  5. (NCRE网络技术)网络安全技术-知识点
  6. Excel第24享:替换函数之SUBSTITUTE函数与REPLACE函数
  7. python做量化交易
  8. 【苹果家庭推位置推送】软件安装许子fkapple就相当于遵守了eatable协议
  9. 人才网站的盈利思路(1)
  10. Java知识体系总结(2020版)