android仿支付宝输入车牌号
这个是iOS的效果图,差异不大,楼主主攻OC,见谅

需要用到的xml文件

需要用到的类

number_or_letters.xml
<?xml version="1.0" encoding="UTF-8"?>
<Keyboard android:keyWidth="10%p" android:keyHeight="8%"
android:horizontalGap="0.0px" android:verticalGap="0.0px"
xmlns:android="http://schemas.android.com/apk/res/android">
<Row android:verticalGap="1%p">
<Key android:codes="49" android:keyLabel="1"
android:horizontalGap="1%p" android:keyWidth="8%p"
android:keyEdgeFlags="left" />
<Key android:codes="50" android:keyLabel="2"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="51" android:keyLabel="3"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="52" android:keyLabel="4"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="53" android:keyLabel="5"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="54" android:keyLabel="6"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="55" android:keyLabel="7"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="56" android:keyLabel="8"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="57" android:keyLabel="9"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="48" android:keyLabel="0"
android:horizontalGap="2%p" android:keyWidth="8%p"
android:keyEdgeFlags="right"/>
</Row> <Row android:verticalGap="1%p">
<Key android:codes="81" android:keyLabel="Q"
android:horizontalGap="1%p" android:keyWidth="8%p"
android:keyEdgeFlags="left" />
<Key android:codes="87" android:keyLabel="W"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="69" android:keyLabel="E"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="82" android:keyLabel="R"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="84" android:keyLabel="T"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="89" android:keyLabel="Y"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="85" android:keyLabel="U"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="73" android:keyLabel="I"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="79" android:keyLabel="O"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="80" android:keyLabel="P"
android:horizontalGap="2%p" android:keyWidth="8%p"
android:keyEdgeFlags="right" />
</Row> <Row android:verticalGap="1%p">
<Key android:codes="65" android:keyLabel="A"
android:horizontalGap="6%p" android:keyWidth="8%p"
android:keyEdgeFlags="left"/>
<Key android:codes="83" android:keyLabel="S"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="68" android:keyLabel="D"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="70" android:keyLabel="F"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="71" android:keyLabel="G"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="72" android:keyLabel="H"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="74" android:keyLabel="J"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="75" android:keyLabel="K"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="76" android:keyLabel="L"
android:horizontalGap="2%p" android:keyWidth="8%p"
android:keyEdgeFlags="right" />
</Row> <Row >
<Key android:codes="-1"
android:keyEdgeFlags="left" android:keyLabel="省份"
android:horizontalGap="1%p" android:keyWidth="13%p"
android:isModifier="true" android:isSticky="true" />
<Key android:codes="90" android:keyLabel="Z"
android:horizontalGap="2%p" android:keyWidth="8%p"/>
<Key android:codes="88" android:keyLabel="X"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="67" android:keyLabel="C"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="86" android:keyLabel="V"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="66" android:keyLabel="B"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="78" android:keyLabel="N"
android:horizontalGap="2%p" android:keyWidth="8%p"/>
<Key android:codes="77" android:keyLabel="M"
android:horizontalGap="2%p" android:keyWidth="8%p"/>
<Key android:codes="-3"
android:keyEdgeFlags="right" android:keyLabel="删除"
android:horizontalGap="2%p" android:keyWidth="13%p"
android:isRepeatable="false" />
</Row> </Keyboard>
province_abbreviation.xml
<?xml version="1.0" encoding="UTF-8"?>
<Keyboard
android:keyWidth="10%p" android:keyHeight="8%p"
android:horizontalGap="0.0px" android:verticalGap="0.0px"
xmlns:android="http://schemas.android.com/apk/res/android"> <Row android:verticalGap="1%p">
<Key android:codes="20140" android:keyLabel="京"
android:horizontalGap="1%p" android:keyWidth="8%p"
android:keyEdgeFlags="left" />
<Key android:codes="27941" android:keyLabel="津"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="20864" android:keyLabel="冀"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="40065" android:keyLabel="鲁"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="26187" android:keyLabel="晋"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="33945" android:keyLabel="蒙"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="36797" android:keyLabel="辽"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="21513" android:keyLabel="吉"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="40657" android:keyLabel="黑"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="27818" android:keyLabel="沪"
android:horizontalGap="2%p" android:keyWidth="8%p"
android:keyEdgeFlags="right"/>
</Row> <Row android:verticalGap="1%p">
<Key android:codes="33487" android:keyLabel="苏"
android:horizontalGap="1%p" android:keyWidth="8%p"
android:keyEdgeFlags="left" />
<Key android:codes="27993" android:keyLabel="浙"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="30358" android:keyLabel="皖"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="38397" android:keyLabel="闽"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="36195" android:keyLabel="赣"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="35947" android:keyLabel="豫"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="37122" android:keyLabel="鄂"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="28248" android:keyLabel="湘"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="31908" android:keyLabel="粤"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="26690" android:keyLabel="桂"
android:horizontalGap="2%p" android:keyWidth="8%p"
android:keyEdgeFlags="right" />
</Row> <Row android:verticalGap="1%p">
<Key android:codes="28189" android:keyLabel="渝"
android:horizontalGap="11%p" android:keyWidth="8%p"
android:keyEdgeFlags="left"/>
<Key android:codes="24029" android:keyLabel="川"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="36149" android:keyLabel="贵"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="20113" android:keyLabel="云"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="34255" android:keyLabel="藏"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="38485" android:keyLabel="陕"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="29976" android:keyLabel="甘"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="38738" android:keyLabel="青"
android:horizontalGap="2%p" android:keyWidth="8%p"
android:keyEdgeFlags="right" />
</Row> <Row >
<Key android:codes="-1"
android:keyEdgeFlags="left" android:keyLabel="ABC"
android:horizontalGap="4%p" android:keyWidth="15%p"
android:isModifier="true" android:isSticky="true" />
<Key android:codes="29756" android:keyLabel="琼"
android:horizontalGap="2%p" android:keyWidth="8%p"/>
<Key android:codes="26032" android:keyLabel="新"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="23425" android:keyLabel="宁"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="28207" android:keyLabel="港"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="28595" android:keyLabel="澳"
android:horizontalGap="2%p" android:keyWidth="8%p" />
<Key android:codes="21488" android:keyLabel="台"
android:horizontalGap="2%p" android:keyWidth="8%p"/>
<Key android:codes="-3"
android:keyEdgeFlags="right" android:keyLabel="删除"
android:horizontalGap="2%p" android:keyWidth="15%p"
android:isRepeatable="false" />
</Row> </Keyboard>
KeyboardUtil.java
public class KeyboardUtil {
private Activity mActivity;
private KeyboardView mKeyboardView;
private EditText mEdit;
/**
* 省份简称键盘
*/
private Keyboard provinceKeyboard;
/**
* 数字与大写字母键盘
*/
private Keyboard numberKeyboard;
public KeyboardUtil(Activity activity, EditText edit) {
mActivity = activity;
mEdit = edit;
provinceKeyboard = new Keyboard(activity, R.xml.province_abbreviation);
numberKeyboard = new Keyboard(activity, R.xml.number_or_letters);
mKeyboardView = (KeyboardView) activity.findViewById(R.id.keyboard_view);
mKeyboardView.setKeyboard(provinceKeyboard);
mKeyboardView.setEnabled(true);
mKeyboardView.setPreviewEnabled(false);
mKeyboardView.setOnKeyboardActionListener(listener);
}
private KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() {
@Override
public void swipeUp() {
}
@Override
public void swipeRight() {
}
@Override
public void swipeLeft() {
}
@Override
public void swipeDown() {
}
@Override
public void onText(CharSequence text) {
}
@Override
public void onRelease(int primaryCode) {
}
@Override
public void onPress(int primaryCode) {
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
Editable editable = mEdit.getText();
int start = mEdit.getSelectionStart();
//判定是否是中文的正则表达式 [\\u4e00-\\u9fa5]判断一个中文 [\\u4e00-\\u9fa5]+多个中文
String reg = "[\\u4e00-\\u9fa5]";
if (primaryCode == -1) {// 省份简称与数字键盘切换
if (mEdit.getText().toString().matches(reg)) {
changeKeyboard(true);
}
} else if (primaryCode == -3) {
if (editable != null && editable.length() > 0) {
//没有输入内容时软键盘重置为省份简称软键盘
if (editable.length() == 1) {
changeKeyboard(false);
}
if (start > 0) {
editable.delete(start - 1, start);
}
}
} else {
editable.insert(start, Character.toString((char) primaryCode));
// 判断第一个字符是否是中文,是,则自动切换到数字软键盘
if (mEdit.getText().toString().matches(reg)) {
changeKeyboard(true);
}
}
}
};
/**
* 指定切换软键盘 isNumber false表示要切换为省份简称软键盘 true表示要切换为数字软键盘
*/
private void changeKeyboard(boolean isNumber) {
if (isNumber) {
mKeyboardView.setKeyboard(numberKeyboard);
} else {
mKeyboardView.setKeyboard(provinceKeyboard);
}
}
/**
* 软键盘展示状态
*/
public boolean isShow() {
if(mKeyboardView == null){
return false;
}
return mKeyboardView.getVisibility() == View.VISIBLE;
}
/**
* 软键盘展示
*/
public void showKeyboard() {
int visibility = mKeyboardView.getVisibility();
if (visibility == View.GONE || visibility == View.INVISIBLE) {
mKeyboardView.setVisibility(View.VISIBLE);
}
}
/**
* 软键盘隐藏
*/
public void hideKeyboard() {
int visibility = mKeyboardView.getVisibility();
if (visibility == View.VISIBLE) {
mKeyboardView.setVisibility(View.INVISIBLE);
}
}
/**
* 禁掉系统软键盘
*/
public void hideSoftInputMethod() {
mActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
int currentVersion = android.os.Build.VERSION.SDK_INT;
String methodName = null;
if (currentVersion >= 16) {
// 4.2
methodName = "setShowSoftInputOnFocus";
} else if (currentVersion >= 14) {
// 4.0
methodName = "setSoftInputShownOnFocus";
}
if (methodName == null) {
mEdit.setInputType(InputType.TYPE_NULL);
} else {
Class<EditText> cls = EditText.class;
Method setShowSoftInputOnFocus;
try {
setShowSoftInputOnFocus = cls.getMethod(methodName, boolean.class);
setShowSoftInputOnFocus.setAccessible(true);
setShowSoftInputOnFocus.invoke(mEdit, false);
} catch (NoSuchMethodException e) {
mEdit.setInputType(InputType.TYPE_NULL);
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
使用:
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboard_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#DCDCDC"
android:focusable="true"
android:focusableInTouchMode="true"
android:keyBackground="@drawable/radius5"
android:keyTextColor="#000"
android:keyTextSize="18sp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:shadowColor="#FFFFFF"
android:shadowRadius="0.0"
android:visibility="gone"/>
licese = (EditText) findViewById(R.id.licese);
licese.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
if (keyboardUtil == null) {
keyboardUtil = new KeyboardUtil(JumpScanActivity.this, licese);
keyboardUtil.hideSoftInputMethod();
keyboardUtil.showKeyboard();
} else {
keyboardUtil.showKeyboard();
}
return false;
}
});
android仿支付宝输入车牌号的更多相关文章
- KeyboardDemo - Android身份证号、车牌号快捷输入键盘
Android身份证号.车牌号快捷输入键盘 项目地址 Github 键盘部分在 keyboard module 中 键盘与EditText绑定参照 MainActivity
- OC仿支付宝输入UITextField输入车牌号
效果图,如果使用,出现任何问题请告知,或者下方留言,我好以及改正 .h文件: #import <UIKit/UIKit.h> @interface LicenseKeyBoardView ...
- Android中手机号、车牌号正则表达式
手机号 手机号的号段说明转载自:国内手机号码的正则表达式|蜗牛的积累 手机名称有GSM:表示只支持中国联通或者中国移动2G号段(130.131.132.134.135.136.137.138.139. ...
- jQuery移动端手机键盘输入车牌号代码【附加新能源车牌】
最近在移动应用中要做到一个录取汽车牌号码的功能,在网上找了一个插件后发现没有增加新能源车牌功能, 和同事研究了一下,将其进行改造完美的实现了这个功能,这里放出该插件的源码: 原插件来自A5源码网[ht ...
- Android仿支付宝扣款顺序,动态改变ListView各Item次序
前言:今天遇到个需求,需要让用户动态选择语音传输方式的次序,突然想起支付宝选择扣款顺序的功能,恰好能满足需要,就花了点时间写了个demo,在此权当学习记录 先上效果图 支付宝的效果 demo的效果 思 ...
- Android仿支付宝高顶部功能条伸缩动画
参考:https://blog.csdn.net/aqi00/article/details/72621176
- Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像
此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...
- Android特效专辑(十二)——仿支付宝咻一咻功能实现波纹扩散特效,精细小巧的View
Android特效专辑(十二)--仿支付宝咻一咻功能实现波纹扩散特效,精细小巧的View 先来看看这个效果 这是我的在Only上添加的效果,说实话,Only现在都还只是半成品,台面都上不了,怪自己技术 ...
- Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现
Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现 2015-03-10 22:38 28419人阅读 评论(17) 收藏 举报 分类: Android ...
随机推荐
- react 生命周期钩子里不要写逻辑,否则不生效
react 生命周期钩子里不要写逻辑,否则不生效,要把逻辑写在函数里,然后在钩子里调用函数,否则会出现问题.
- Java -- POI -- 随笔汇总
1. 判断指定的单元格是否是合并单元格 /** * 功能:判断指定的单元格是否是合并单元格 * 原理:excel中的合并单元格其实就是首单元格,只不过该单元格增加了 rowspan和colspan两个 ...
- iOS shell脚本打包
原文链接:http://www.jianshu.com/p/5abbe0d61cef 参考链接:http://blog.csdn.net/potato512/article/details/52176 ...
- H5网页适配 iPhoneX,就是这么简单(转)
iPhoneX 取消了物理按键,改成底部小黑条,这一改动导致网页出现了比较尴尬的屏幕适配问题.对于网页而言,顶部(刘海部位)的适配问题浏览器已经做了处理,所以我们只需要关注底部与小黑条的适配问题即可( ...
- JQuery EasyUI DataGrid获取当前行
1.获取当前行索引 var rowIndex = $('#dg').datagrid('getRowIndex', row); 2.根据索引删除当前行 $('#dg').datagrid('delet ...
- AngularJS基础01 从HelloWorld说起
作者:arccosxy 转载请注明出处:http://www.cnblogs.com/arccosxy/ 准备工作 首先,创建一个名为index.html的HTML文件,代码如下: <!DOC ...
- zynq里面的AXI总线(2017-1-11)
在ZYNQ中有支持三种AXI总线,拥有三种AXI接口,当然用的都是AXI协议.其中三种AXI总线分别为: AXI4:(For high-performance memory-mapped requir ...
- MySQL设置只读模式
MySQL设置了主从复制,为保证数据一致性需要在从库设置只读状态 查看默认读写状态 show global variables like "%read_only%"; 设置只读 # ...
- java基础解析系列(二)---Integer
java基础解析系列(二)---Integer 前言:本系列的主题是平时容易疏忽的知识点,只有基础扎实,在编码的时候才能更注重规范和性能,在出现bug的时候,才能处理更加从容. 目录 java基础解析 ...
- Hadoop开发环境配置2-eclipse集成maven插件
1.下载eclipse:eclipse-SDK-4.5-win32-x86_64.zip 下载地址: http://archive.eclipse.org/eclipse/downloads/drop ...