这个是iOS的效果图,差异不大,楼主主攻OC,见谅

需要用到的xml文件

需要用到的类

number_or_letters.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Keyboard android:keyWidth="10%p" android:keyHeight="8%"
  3. android:horizontalGap="0.0px" android:verticalGap="0.0px"
  4. xmlns:android="http://schemas.android.com/apk/res/android">
  5. <Row android:verticalGap="1%p">
  6. <Key android:codes="49" android:keyLabel="1"
  7. android:horizontalGap="1%p" android:keyWidth="8%p"
  8. android:keyEdgeFlags="left" />
  9. <Key android:codes="50" android:keyLabel="2"
  10. android:horizontalGap="2%p" android:keyWidth="8%p" />
  11. <Key android:codes="51" android:keyLabel="3"
  12. android:horizontalGap="2%p" android:keyWidth="8%p" />
  13. <Key android:codes="52" android:keyLabel="4"
  14. android:horizontalGap="2%p" android:keyWidth="8%p" />
  15. <Key android:codes="53" android:keyLabel="5"
  16. android:horizontalGap="2%p" android:keyWidth="8%p" />
  17. <Key android:codes="54" android:keyLabel="6"
  18. android:horizontalGap="2%p" android:keyWidth="8%p" />
  19. <Key android:codes="55" android:keyLabel="7"
  20. android:horizontalGap="2%p" android:keyWidth="8%p" />
  21. <Key android:codes="56" android:keyLabel="8"
  22. android:horizontalGap="2%p" android:keyWidth="8%p" />
  23. <Key android:codes="57" android:keyLabel="9"
  24. android:horizontalGap="2%p" android:keyWidth="8%p" />
  25. <Key android:codes="48" android:keyLabel="0"
  26. android:horizontalGap="2%p" android:keyWidth="8%p"
  27. android:keyEdgeFlags="right"/>
  28. </Row>
  29.  
  30. <Row android:verticalGap="1%p">
  31. <Key android:codes="81" android:keyLabel="Q"
  32. android:horizontalGap="1%p" android:keyWidth="8%p"
  33. android:keyEdgeFlags="left" />
  34. <Key android:codes="87" android:keyLabel="W"
  35. android:horizontalGap="2%p" android:keyWidth="8%p" />
  36. <Key android:codes="69" android:keyLabel="E"
  37. android:horizontalGap="2%p" android:keyWidth="8%p" />
  38. <Key android:codes="82" android:keyLabel="R"
  39. android:horizontalGap="2%p" android:keyWidth="8%p" />
  40. <Key android:codes="84" android:keyLabel="T"
  41. android:horizontalGap="2%p" android:keyWidth="8%p" />
  42. <Key android:codes="89" android:keyLabel="Y"
  43. android:horizontalGap="2%p" android:keyWidth="8%p" />
  44. <Key android:codes="85" android:keyLabel="U"
  45. android:horizontalGap="2%p" android:keyWidth="8%p" />
  46. <Key android:codes="73" android:keyLabel="I"
  47. android:horizontalGap="2%p" android:keyWidth="8%p" />
  48. <Key android:codes="79" android:keyLabel="O"
  49. android:horizontalGap="2%p" android:keyWidth="8%p" />
  50. <Key android:codes="80" android:keyLabel="P"
  51. android:horizontalGap="2%p" android:keyWidth="8%p"
  52. android:keyEdgeFlags="right" />
  53. </Row>
  54.  
  55. <Row android:verticalGap="1%p">
  56. <Key android:codes="65" android:keyLabel="A"
  57. android:horizontalGap="6%p" android:keyWidth="8%p"
  58. android:keyEdgeFlags="left"/>
  59. <Key android:codes="83" android:keyLabel="S"
  60. android:horizontalGap="2%p" android:keyWidth="8%p" />
  61. <Key android:codes="68" android:keyLabel="D"
  62. android:horizontalGap="2%p" android:keyWidth="8%p" />
  63. <Key android:codes="70" android:keyLabel="F"
  64. android:horizontalGap="2%p" android:keyWidth="8%p" />
  65. <Key android:codes="71" android:keyLabel="G"
  66. android:horizontalGap="2%p" android:keyWidth="8%p" />
  67. <Key android:codes="72" android:keyLabel="H"
  68. android:horizontalGap="2%p" android:keyWidth="8%p" />
  69. <Key android:codes="74" android:keyLabel="J"
  70. android:horizontalGap="2%p" android:keyWidth="8%p" />
  71. <Key android:codes="75" android:keyLabel="K"
  72. android:horizontalGap="2%p" android:keyWidth="8%p" />
  73. <Key android:codes="76" android:keyLabel="L"
  74. android:horizontalGap="2%p" android:keyWidth="8%p"
  75. android:keyEdgeFlags="right" />
  76. </Row>
  77.  
  78. <Row >
  79. <Key android:codes="-1"
  80. android:keyEdgeFlags="left" android:keyLabel="省份"
  81. android:horizontalGap="1%p" android:keyWidth="13%p"
  82. android:isModifier="true" android:isSticky="true" />
  83. <Key android:codes="90" android:keyLabel="Z"
  84. android:horizontalGap="2%p" android:keyWidth="8%p"/>
  85. <Key android:codes="88" android:keyLabel="X"
  86. android:horizontalGap="2%p" android:keyWidth="8%p" />
  87. <Key android:codes="67" android:keyLabel="C"
  88. android:horizontalGap="2%p" android:keyWidth="8%p" />
  89. <Key android:codes="86" android:keyLabel="V"
  90. android:horizontalGap="2%p" android:keyWidth="8%p" />
  91. <Key android:codes="66" android:keyLabel="B"
  92. android:horizontalGap="2%p" android:keyWidth="8%p" />
  93. <Key android:codes="78" android:keyLabel="N"
  94. android:horizontalGap="2%p" android:keyWidth="8%p"/>
  95. <Key android:codes="77" android:keyLabel="M"
  96. android:horizontalGap="2%p" android:keyWidth="8%p"/>
  97. <Key android:codes="-3"
  98. android:keyEdgeFlags="right" android:keyLabel="删除"
  99. android:horizontalGap="2%p" android:keyWidth="13%p"
  100. android:isRepeatable="false" />
  101. </Row>
  102.  
  103. </Keyboard>
 

province_abbreviation.xml

 
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Keyboard
  3. android:keyWidth="10%p" android:keyHeight="8%p"
  4. android:horizontalGap="0.0px" android:verticalGap="0.0px"
  5. xmlns:android="http://schemas.android.com/apk/res/android">
  6.  
  7. <Row android:verticalGap="1%p">
  8. <Key android:codes="20140" android:keyLabel="京"
  9. android:horizontalGap="1%p" android:keyWidth="8%p"
  10. android:keyEdgeFlags="left" />
  11. <Key android:codes="27941" android:keyLabel="津"
  12. android:horizontalGap="2%p" android:keyWidth="8%p" />
  13. <Key android:codes="20864" android:keyLabel="冀"
  14. android:horizontalGap="2%p" android:keyWidth="8%p" />
  15. <Key android:codes="40065" android:keyLabel="鲁"
  16. android:horizontalGap="2%p" android:keyWidth="8%p" />
  17. <Key android:codes="26187" android:keyLabel="晋"
  18. android:horizontalGap="2%p" android:keyWidth="8%p" />
  19. <Key android:codes="33945" android:keyLabel="蒙"
  20. android:horizontalGap="2%p" android:keyWidth="8%p" />
  21. <Key android:codes="36797" android:keyLabel="辽"
  22. android:horizontalGap="2%p" android:keyWidth="8%p" />
  23. <Key android:codes="21513" android:keyLabel="吉"
  24. android:horizontalGap="2%p" android:keyWidth="8%p" />
  25. <Key android:codes="40657" android:keyLabel="黑"
  26. android:horizontalGap="2%p" android:keyWidth="8%p" />
  27. <Key android:codes="27818" android:keyLabel="沪"
  28. android:horizontalGap="2%p" android:keyWidth="8%p"
  29. android:keyEdgeFlags="right"/>
  30. </Row>
  31.  
  32. <Row android:verticalGap="1%p">
  33. <Key android:codes="33487" android:keyLabel="苏"
  34. android:horizontalGap="1%p" android:keyWidth="8%p"
  35. android:keyEdgeFlags="left" />
  36. <Key android:codes="27993" android:keyLabel="浙"
  37. android:horizontalGap="2%p" android:keyWidth="8%p" />
  38. <Key android:codes="30358" android:keyLabel="皖"
  39. android:horizontalGap="2%p" android:keyWidth="8%p" />
  40. <Key android:codes="38397" android:keyLabel="闽"
  41. android:horizontalGap="2%p" android:keyWidth="8%p" />
  42. <Key android:codes="36195" android:keyLabel="赣"
  43. android:horizontalGap="2%p" android:keyWidth="8%p" />
  44. <Key android:codes="35947" android:keyLabel="豫"
  45. android:horizontalGap="2%p" android:keyWidth="8%p" />
  46. <Key android:codes="37122" android:keyLabel="鄂"
  47. android:horizontalGap="2%p" android:keyWidth="8%p" />
  48. <Key android:codes="28248" android:keyLabel="湘"
  49. android:horizontalGap="2%p" android:keyWidth="8%p" />
  50. <Key android:codes="31908" android:keyLabel="粤"
  51. android:horizontalGap="2%p" android:keyWidth="8%p" />
  52. <Key android:codes="26690" android:keyLabel="桂"
  53. android:horizontalGap="2%p" android:keyWidth="8%p"
  54. android:keyEdgeFlags="right" />
  55. </Row>
  56.  
  57. <Row android:verticalGap="1%p">
  58. <Key android:codes="28189" android:keyLabel="渝"
  59. android:horizontalGap="11%p" android:keyWidth="8%p"
  60. android:keyEdgeFlags="left"/>
  61. <Key android:codes="24029" android:keyLabel="川"
  62. android:horizontalGap="2%p" android:keyWidth="8%p" />
  63. <Key android:codes="36149" android:keyLabel="贵"
  64. android:horizontalGap="2%p" android:keyWidth="8%p" />
  65. <Key android:codes="20113" android:keyLabel="云"
  66. android:horizontalGap="2%p" android:keyWidth="8%p" />
  67. <Key android:codes="34255" android:keyLabel="藏"
  68. android:horizontalGap="2%p" android:keyWidth="8%p" />
  69. <Key android:codes="38485" android:keyLabel="陕"
  70. android:horizontalGap="2%p" android:keyWidth="8%p" />
  71. <Key android:codes="29976" android:keyLabel="甘"
  72. android:horizontalGap="2%p" android:keyWidth="8%p" />
  73. <Key android:codes="38738" android:keyLabel="青"
  74. android:horizontalGap="2%p" android:keyWidth="8%p"
  75. android:keyEdgeFlags="right" />
  76. </Row>
  77.  
  78. <Row >
  79. <Key android:codes="-1"
  80. android:keyEdgeFlags="left" android:keyLabel="ABC"
  81. android:horizontalGap="4%p" android:keyWidth="15%p"
  82. android:isModifier="true" android:isSticky="true" />
  83. <Key android:codes="29756" android:keyLabel="琼"
  84. android:horizontalGap="2%p" android:keyWidth="8%p"/>
  85. <Key android:codes="26032" android:keyLabel="新"
  86. android:horizontalGap="2%p" android:keyWidth="8%p" />
  87. <Key android:codes="23425" android:keyLabel="宁"
  88. android:horizontalGap="2%p" android:keyWidth="8%p" />
  89. <Key android:codes="28207" android:keyLabel="港"
  90. android:horizontalGap="2%p" android:keyWidth="8%p" />
  91. <Key android:codes="28595" android:keyLabel="澳"
  92. android:horizontalGap="2%p" android:keyWidth="8%p" />
  93. <Key android:codes="21488" android:keyLabel="台"
  94. android:horizontalGap="2%p" android:keyWidth="8%p"/>
  95. <Key android:codes="-3"
  96. android:keyEdgeFlags="right" android:keyLabel="删除"
  97. android:horizontalGap="2%p" android:keyWidth="15%p"
  98. android:isRepeatable="false" />
  99. </Row>
  100.  
  101. </Keyboard>
  1. KeyboardUtil.java
  1. public class KeyboardUtil {
  2. private Activity mActivity;
  3. private KeyboardView mKeyboardView;
  4. private EditText mEdit;
  5. /**
  6. * 省份简称键盘
  7. */
  8. private Keyboard provinceKeyboard;
  9. /**
  10. * 数字与大写字母键盘
  11. */
  12. private Keyboard numberKeyboard;
  13.  
  14. public KeyboardUtil(Activity activity, EditText edit) {
  15. mActivity = activity;
  16. mEdit = edit;
  17. provinceKeyboard = new Keyboard(activity, R.xml.province_abbreviation);
  18. numberKeyboard = new Keyboard(activity, R.xml.number_or_letters);
  19. mKeyboardView = (KeyboardView) activity.findViewById(R.id.keyboard_view);
  20. mKeyboardView.setKeyboard(provinceKeyboard);
  21. mKeyboardView.setEnabled(true);
  22. mKeyboardView.setPreviewEnabled(false);
  23. mKeyboardView.setOnKeyboardActionListener(listener);
  24. }
  25.  
  26. private KeyboardView.OnKeyboardActionListener listener = new KeyboardView.OnKeyboardActionListener() {
  27. @Override
  28. public void swipeUp() {
  29. }
  30.  
  31. @Override
  32. public void swipeRight() {
  33. }
  34.  
  35. @Override
  36. public void swipeLeft() {
  37. }
  38.  
  39. @Override
  40. public void swipeDown() {
  41. }
  42.  
  43. @Override
  44. public void onText(CharSequence text) {
  45.  
  46. }
  47.  
  48. @Override
  49. public void onRelease(int primaryCode) {
  50. }
  51.  
  52. @Override
  53. public void onPress(int primaryCode) {
  54. }
  55.  
  56. @Override
  57. public void onKey(int primaryCode, int[] keyCodes) {
  58. Editable editable = mEdit.getText();
  59. int start = mEdit.getSelectionStart();
  60. //判定是否是中文的正则表达式 [\\u4e00-\\u9fa5]判断一个中文 [\\u4e00-\\u9fa5]+多个中文
  61. String reg = "[\\u4e00-\\u9fa5]";
  62. if (primaryCode == -1) {// 省份简称与数字键盘切换
  63. if (mEdit.getText().toString().matches(reg)) {
  64. changeKeyboard(true);
  65. }
  66. } else if (primaryCode == -3) {
  67. if (editable != null && editable.length() > 0) {
  68. //没有输入内容时软键盘重置为省份简称软键盘
  69. if (editable.length() == 1) {
  70. changeKeyboard(false);
  71. }
  72. if (start > 0) {
  73. editable.delete(start - 1, start);
  74. }
  75. }
  76. } else {
  77. editable.insert(start, Character.toString((char) primaryCode));
  78. // 判断第一个字符是否是中文,是,则自动切换到数字软键盘
  79. if (mEdit.getText().toString().matches(reg)) {
  80. changeKeyboard(true);
  81. }
  82. }
  83. }
  84. };
  85.  
  86. /**
  87. * 指定切换软键盘 isNumber false表示要切换为省份简称软键盘 true表示要切换为数字软键盘
  88. */
  89. private void changeKeyboard(boolean isNumber) {
  90. if (isNumber) {
  91. mKeyboardView.setKeyboard(numberKeyboard);
  92. } else {
  93. mKeyboardView.setKeyboard(provinceKeyboard);
  94. }
  95. }
  96.  
  97. /**
  98. * 软键盘展示状态
  99. */
  100. public boolean isShow() {
  101. if(mKeyboardView == null){
  102. return false;
  103. }
  104. return mKeyboardView.getVisibility() == View.VISIBLE;
  105. }
  106.  
  107. /**
  108. * 软键盘展示
  109. */
  110. public void showKeyboard() {
  111. int visibility = mKeyboardView.getVisibility();
  112. if (visibility == View.GONE || visibility == View.INVISIBLE) {
  113. mKeyboardView.setVisibility(View.VISIBLE);
  114. }
  115. }
  116.  
  117. /**
  118. * 软键盘隐藏
  119. */
  120. public void hideKeyboard() {
  121. int visibility = mKeyboardView.getVisibility();
  122. if (visibility == View.VISIBLE) {
  123. mKeyboardView.setVisibility(View.INVISIBLE);
  124. }
  125. }
  126.  
  127. /**
  128. * 禁掉系统软键盘
  129. */
  130. public void hideSoftInputMethod() {
  131. mActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  132. int currentVersion = android.os.Build.VERSION.SDK_INT;
  133. String methodName = null;
  134. if (currentVersion >= 16) {
  135. // 4.2
  136. methodName = "setShowSoftInputOnFocus";
  137. } else if (currentVersion >= 14) {
  138. // 4.0
  139. methodName = "setSoftInputShownOnFocus";
  140. }
  141. if (methodName == null) {
  142. mEdit.setInputType(InputType.TYPE_NULL);
  143. } else {
  144. Class<EditText> cls = EditText.class;
  145. Method setShowSoftInputOnFocus;
  146. try {
  147. setShowSoftInputOnFocus = cls.getMethod(methodName, boolean.class);
  148. setShowSoftInputOnFocus.setAccessible(true);
  149. setShowSoftInputOnFocus.invoke(mEdit, false);
  150. } catch (NoSuchMethodException e) {
  151. mEdit.setInputType(InputType.TYPE_NULL);
  152. e.printStackTrace();
  153. } catch (IllegalAccessException e) {
  154. e.printStackTrace();
  155. } catch (IllegalArgumentException e) {
  156. e.printStackTrace();
  157. } catch (InvocationTargetException e) {
  158. e.printStackTrace();
  159. }
  160. }
  161. }
  162.  
  163. }

使用:

  1. <android.inputmethodservice.KeyboardView
  2. android:id="@+id/keyboard_view"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:layout_alignParentBottom="true"
  6. android:background="#DCDCDC"
  7. android:focusable="true"
  8. android:focusableInTouchMode="true"
  9. android:keyBackground="@drawable/radius5"
  10. android:keyTextColor="#000"
  11. android:keyTextSize="18sp"
  12. android:paddingBottom="8dp"
  13. android:paddingTop="8dp"
  14. android:shadowColor="#FFFFFF"
  15. android:shadowRadius="0.0"
  16. android:visibility="gone"/>
  1. licese = (EditText) findViewById(R.id.licese);
  2. licese.setOnTouchListener(new View.OnTouchListener() {
  3. @Override
  4. public boolean onTouch(View view, MotionEvent event) {
  5. if (keyboardUtil == null) {
  6. keyboardUtil = new KeyboardUtil(JumpScanActivity.this, licese);
  7. keyboardUtil.hideSoftInputMethod();
  8. keyboardUtil.showKeyboard();
  9. } else {
  10. keyboardUtil.showKeyboard();
  11. }
  12. return false;
  13. }
  14. });

android仿支付宝输入车牌号的更多相关文章

  1. KeyboardDemo - Android身份证号、车牌号快捷输入键盘

    Android身份证号.车牌号快捷输入键盘 项目地址 Github 键盘部分在 keyboard module 中 键盘与EditText绑定参照 MainActivity

  2. OC仿支付宝输入UITextField输入车牌号

    效果图,如果使用,出现任何问题请告知,或者下方留言,我好以及改正 .h文件: #import <UIKit/UIKit.h> @interface LicenseKeyBoardView ...

  3. Android中手机号、车牌号正则表达式

    手机号 手机号的号段说明转载自:国内手机号码的正则表达式|蜗牛的积累 手机名称有GSM:表示只支持中国联通或者中国移动2G号段(130.131.132.134.135.136.137.138.139. ...

  4. jQuery移动端手机键盘输入车牌号代码【附加新能源车牌】

    最近在移动应用中要做到一个录取汽车牌号码的功能,在网上找了一个插件后发现没有增加新能源车牌功能, 和同事研究了一下,将其进行改造完美的实现了这个功能,这里放出该插件的源码: 原插件来自A5源码网[ht ...

  5. Android仿支付宝扣款顺序,动态改变ListView各Item次序

    前言:今天遇到个需求,需要让用户动态选择语音传输方式的次序,突然想起支付宝选择扣款顺序的功能,恰好能满足需要,就花了点时间写了个demo,在此权当学习记录 先上效果图 支付宝的效果 demo的效果 思 ...

  6. Android仿支付宝高顶部功能条伸缩动画

    参考:https://blog.csdn.net/aqi00/article/details/72621176

  7. Android控件Gridview实现仿支付宝首页,Fragment底部按钮切换和登录圆形头像

    此案例主要讲的是Android控件Gridview(九宫格)完美实现仿支付宝首页,包含添加和删除功能:Fragment底部按钮切换的效果,包含四个模块,登录页面圆形头像等,一个小项目的初始布局. 效果 ...

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

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

  9. Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现

    Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现 2015-03-10 22:38 28419人阅读 评论(17) 收藏 举报  分类: Android ...

随机推荐

  1. [SLAM] ***AR Tracking based on which tools?

    SLAM虽然小复杂,但对于开发者而言,ar sdk通常会解决这个问题. 所以相对于识别,跟踪是个看上去高大上但实则不需要关注细节的部分. 识别,要技术深耕:跟踪,需行业深耕. 在此了解下常见的ar s ...

  2. 09观察者模式ObServer

    一.什么是观察者模式 Observer模式是行为模式之一,它的作用是当 一个对象的状态发生变化时,能够自动通知其他 关联对象,自动刷新对象状态. Observer模式提供给关联对象一种同步通信的 手段 ...

  3. MVC和普通三层架构的区别

    MVC和普通三层架构的区别 其中这里的模型(Model)和视图(View )是完全区别于三层架构中的模型(Model)和视图(View)的. MVC 1)MVC中的模型(Model)指的是数据模型,用 ...

  4. VS Code非英语版本连接TFS错误解决方案

    使用VS Code连接TFS时,提示以下错误: (team) It appears you have configured a non-English version of the TF execut ...

  5. Python中通过lambda抛异常的奇技淫巧

    假设我们需要一个函数什么事都不干,只是抛出异常(在某些系统中有些handler就是干这事的),我们可以很直观的写出下面的代码: def func(): raise Exception("th ...

  6. hashlib

    登录认证 加密 --> 解密 摘要算法 两个字符串 : import hashlib # 提供摘要算法的模块 md5 = hashlib.md5() md5.update(b') print(m ...

  7. 10.9 Xadmin

    2018-10-9 13:53:39

  8. 如何实现@ResponseBody,把Json字符串转换为指定类型

    1.问题 spring 是如何把 http中的body,转换为指定类的,里面的难点其实在于泛型的处理. 2.Spring的处理 2.1 HandlerMethod 这个类Spring对Method的封 ...

  9. Jenkins设置备份

    安装备份插件,系统管理-插件管理 可选插件搜索backup 备份 系统管理-Backup manager 设置备份路径 恢复

  10. iBatis.Net 配置 SQL语句执行 日志

    <configuration> <configSections> ... <sectionGroup name="iBATIS"> <se ...