本文实例为大家分享了Android实现微信支付密码输入框的具体代码,供大家参考,具体内容如下
效果图
项目中使用到了支付密码功能,其实这类界面是比较常用的,涉及支付密码的输入的一般都会用到对的,所以单独地把这部分抽取出来,有需要的朋友可以拿去用哈!
效果就是支付,弹出密码框,输入密码,这个过程密码不可见,并且提供一个输入完毕的监听!
这个弹出层呢,其实就是一个DialogFragment,逻辑封装在其内部
<强>一。弹出层进出动画(动画文件)强>
push_bottom_in.xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; !——上下滑入式——比; & lt;设置xmlns: android=" http://schemas.android.com/apk/res/android "比; & lt;翻译 android:持续时间=" 200 " android: fromYDelta=?00% p” android: toYDelta=" 0 "/比; & lt;/set>
push_bottom_out.xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; !——上下滑出式——比; & lt;设置xmlns: android=" http://schemas.android.com/apk/res/android "比; & lt;翻译 android:持续时间=" 200 " android: fromYDelta=" 0 " android: toYDelta=" p " 100%/比; & lt;/set>
<强>二.drawable资源强>
selector_item_pressed.xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;选择xmlns: android=" http://schemas.android.com/apk/res/android "比; & lt;项目android:可拉的=" @color/gray_bg”android: state_pressed=" true "/比; & lt;项目android:可拉的=" @color/白”android: state_activated=癴alse”/比; & lt;项目android:可拉的=癅color/白”/比; & lt;/selector>
键盘的点击效果
shape_dialog.xml
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt;形状xmlns: android=" http://schemas.android.com/apk/res/android " android:形状=熬匦巍北? & lt;固体android:颜色=癅android:颜色/白色/比; & lt;角落android:半径=" 10 dp/比; & lt;/shape>
弹出框样式
<强>三.mipmap资源强>
ic_arrow_down
<强>四.layout布局强>
fragment_pay.xml
支付弹出层布局
& lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:应用=" http://schemas.android.com/apk/res-auto " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=" match_parent " android: layout_height=癿atch_parent”比; LinearLayout & lt; android: layout_width=" match_parent " android: layout_height=" wrap_content " android: layout_marginLeft=" 40 dp " android: layout_marginRight=" 40 dp " android: layout_marginTop=" 100 dp” android:背景=" @drawable/shape_dialog” android:取向=按怪薄? android: paddingBottom=癅dimen/spacing_large”比; & lt;使用 android: layout_width=" match_parent " android: layout_height=皐rap_content”比; & lt; TextView android: layout_width=" wrap_content " android: layout_height=" @dimen/text_item_height” android: layout_centerInParent=" true " android:重力="中心" android:文本="请输入支付密码” android: textSize=" 20 sp” android: textStyle=按蟮ā?比; & lt; !——取消键——比; & lt; ImageView android: id=癅 + id/iv_close” android:点击=" true " android: layout_width=" 28 dp " android: layout_height=" 28 dp " android: layout_alignParentLeft=" true " android: layout_centerVertical=" true " android: layout_marginLeft=" @dimen/spacing_tiny” android: src=" https://www.yisu.com/zixun/@mipmap icon_del "/比; & lt;/RelativeLayout> & lt;视图/比; & lt; !——操作文字——比; & lt; TextView android: id=癅 + id/tv_content” android: layout_width=" wrap_content " android: layout_height=" @dimen/text_item_height” android: layout_gravity=" center_horizontal " android:重力="中心" android: textStyle=按蟮ā?比; & lt; !——支付金额——比; & lt; TextView android: id=癅 + id/tv_content2” android: layout_width=" wrap_content " android: layout_height=" @dimen/text_item_height” android: layout_gravity=" center_horizontal " android:重力="中心" android: textStyle=按蟮ā?比; & lt; !——额外扣除手续费——比; & lt; TextView android: id=癅 + id/tv_content3” android: layout_width=" wrap_content " android: layout_height=" @dimen/text_item_height2” android: layout_gravity=" center_horizontal " android:重力="中心"/比; & lt; !——密码输入框——比; & lt; cn.xdeveloper.payui.PayPassWordView android: id=癅 + id/payPwdView” android: layout_width=" match_parent " android: layout_height=" wrap_content " android: layout_marginLeft=" @dimen/spacing_large” android: layout_marginRight=" @dimen/spacing_large” android:背景=" @color/白色/比; & lt;/LinearLayout> & lt; !——键盘——比; & lt; cn.xdeveloper.payui.PassWordInputView android: id=癅 + id/inputMethodView” android: layout_width=" match_parent " android: layout_height=" wrap_content " android: layout_alignParentBottom=" true "/比; & lt;/RelativeLayout>Android自定义观点实现微信支付密码输入框