//布局相关
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:id="@+id/k_layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/btn_one"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="1"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/>
<Button
android:id="@+id/btn_two"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="2"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/> <Button
android:id="@+id/btn_three"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:text="3"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/btn_four"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="4"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/>
<Button
android:id="@+id/btn_five"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="5"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/> <Button
android:id="@+id/btn_six"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:text="6"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/btn_seven"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="7"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/>
<Button
android:id="@+id/btn_eight"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="8"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/> <Button
android:id="@+id/btn_nine"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:text="9"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/btn_clear"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="清空"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/>
<Button
android:id="@+id/btn_zero"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:layout_marginRight="10dp"
android:text="0"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/> <Button
android:id="@+id/btn_del"
android:onClick="click_key"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="30dp"
android:text="删除"
android:textSize="18sp"
android:textColor="@color/white"
android:background="@drawable/btn_select_back_t30"/>
</LinearLayout>
</LinearLayout> //.....自己看
editText = (EditText) mView.findViewById(R.id.qc_liangpin);
text = (EditText) mView.findViewById(R.id.qc_buliangping);
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Edit_Tyep = 1;//多个输入框时做的焦点判断
}
});
text.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
Edit_Tyep = 2;
}
});
Button btn0 = (Button) mView.findViewById(R.id.btn_zero);
btn0.setOnClickListener(listener);
Button btn1 = (Button) mView.findViewById(R.id.btn_one);
btn1.setOnClickListener(listener);
Button btn2 = (Button) mView.findViewById(R.id.btn_two);
btn2.setOnClickListener(listener);
Button btn3 = (Button) mView.findViewById(R.id.btn_three);
btn3.setOnClickListener(listener);
Button btn4 = (Button) mView.findViewById(R.id.btn_four);
btn4.setOnClickListener(listener);
Button btn5 = (Button) mView.findViewById(R.id.btn_five);
btn5.setOnClickListener(listener);
Button btn6 = (Button) mView.findViewById(R.id.btn_six);
btn6.setOnClickListener(listener);
Button btn7 = (Button) mView.findViewById(R.id.btn_seven);
btn7.setOnClickListener(listener);
Button btn8 = (Button) mView.findViewById(R.id.btn_eight);
btn8.setOnClickListener(listener);
Button btn9 = (Button) mView.findViewById(R.id.btn_nine);
btn9.setOnClickListener(listener);
Button btndel = (Button) mView.findViewById(R.id.btn_del);
btndel.setOnClickListener(listener);
Button btnclear = (Button) mView.findViewById(R.id.btn_clear);
btnclear.setOnClickListener(listener);
Button.OnClickListener listener = new Button.OnClickListener() {
public void onClick(View v) {
Editable editable = null;
int start = 0;
if (Edit_Tyep == 1) {
editable = editText.getText();
start = editText.getSelectionStart(); } else if (Edit_Tyep == 2) {
editable = text.getText();
start = text.getSelectionStart();
} else {
editable = editText.getText();
start = editText.getSelectionStart();
}
switch (v.getId()) {
case R.id.btn_zero:
editable.insert(start, "0");
break;
case R.id.btn_one:
editable.insert(start, "1");
break;
case R.id.btn_two:
editable.insert(start, "2");
break;
case R.id.btn_three:
editable.insert(start, "3");
break;
case R.id.btn_four:
editable.insert(start, "4");
break;
case R.id.btn_five:
editable.insert(start, "5");
break;
case R.id.btn_six:
editable.insert(start, "6");
break;
case R.id.btn_seven:
editable.insert(start, "7");
break;
case R.id.btn_eight:
editable.insert(start, "8");
break;
case R.id.btn_nine:
editable.insert(start, "9");
break;
case R.id.btn_clear:
if (editable != null)
editable.delete(0, editable.length());
break;
case R.id.btn_del:
if (start > 0)
editable.delete(start - 1, start);
break;
}
}
};
由于时间问题没有 给全代码  关键地方用颜色标出 其实很简单 相信应该能够看懂!

android 数字键盘制作的更多相关文章

  1. pjsip视频通信开发(上层应用)之数字键盘的制作

    在pjsip视频通信开发(上层应用)之EditText重写中我制作了一个显示输入内容的EditText,这里将制作一个数字键盘,其实跟计算器一样,最多的就是用TableLayout来实现,内部通过权重 ...

  2. 【笔记】移动端H5数字键盘input type=number的处理(IOS和Android)

    在Vue中的项目,基于VUX-UI开发,一个常见的需求: 1.金额输入框 2.弹出数字键盘 3.仅支持输入两位小数,限制最大11位数,不允许0开头 后续:与UI沟通后, 思路调整为限制输入,并减少正则 ...

  3. 手机端访问web调用数字键盘。

    转自  http://www.webkfa.com/one4/w1937.html 最近在做手机页面时,遇到数字输入的键盘的问题,之前的做法只是一刀切的使用 type="tel", ...

  4. js Date 函数方法 和 移动端数字键盘调用

    var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-???? ...

  5. Android自定义键盘

    布局文件 <?xml version="1.0" encoding="UTF-8"?> <Keyboard android:keyWidth= ...

  6. [HTML5]移动开发不同手机弹出数字键盘问题

    这里还是先那么先交代一下遇到的问题.其实无论是tel还是number都不是完美的:type="tel"优点是iOS和Android的键盘表现都差不多缺点是那些字母好多余,虽然我没有 ...

  7. SenchaTouch调用纯数字键盘

    items:[ { itemId:"phoneNumber", xtype: "textfield", component:{xtype:"input ...

  8. 一个数字键盘引发的血案——移动端H5输入框、光标、数字键盘全假套件实现

    https://juejin.im/post/5a44c5eef265da432d2868f6 为啥要写假键盘? 还是输入框.光标全假的假键盘? 手机自带的不用非得写个假的,吃饱没事干吧? 装逼?炫技 ...

  9. input 弹起数字键盘的那些坑

    input ios 踩的大坑 前言:最近有个需求要将全平台的交易密码由原来的 6-16位 复杂密码改为6位纯数字交易密码,涉及到非常多的业务场景,但修改起来也无非两种:设置交易密码,使用交易密码 设置 ...

随机推荐

  1. poj 3667 Hotel

    昨天学习了线段树的延迟标记: 发现自己还有区间合并没有学: 抓紧时间学习一下: 代码: #include<cstdio> #include<algorithm> #define ...

  2. mac下设置命令别名

    项目使用了gerrit,每次push代码都需要执行 git push origin HEAD:refs/for/master 为了简便,使用了alias命令来控制台下使用下面的命令简化了提交. ali ...

  3. 【转】linux 中dd命令使用详解

    原文网址:http://xiaozhuang.blog.51cto.com/4396589/850657 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究 ...

  4. ie8此加载项无法恢复&网站还原错误问题解决=lr成功打开ie成功录制脚

    问题:ie8打开公司数字神经时出现此加载项无法恢复,网站还原错误. 解决方法: 1.管理ie加载项,全部禁用以后问题仍然存在,确定不是加载项问题. 2.重设ie8,工具-internet选项-高级-重 ...

  5. 《JavaScript核心概念》基础部分重点摘录

    注:<JavaScript核心概念>适合深入了解JavaScript,比我买的<JavaScript框架设计>语言和内容丰富多了(可能是我水平尚浅吧). 1. 作用域 var ...

  6. java基础(十二)常用类总结(二)

    这里有我之前上课总结的一些知识点以及代码大部分是老师讲的笔记 个人认为是非常好的,,也是比较经典的内容,真诚的希望这些对于那些想学习的人有所帮助! 由于代码是分模块的上传非常的不便.也比较多,讲的也是 ...

  7. zabbix 飞信集成配置

    1.环境说明: (Gentoo Linux环境) # uname -a Linux Crob 2.6.34-gentoo #1 SMP Mon May 31 15:45:25 CST 2010 x86 ...

  8. 【Android - 框架】之可悬浮列表StickyHeadersRecyclerView

    这是timehop的GitHub上发表的一个控件框架,大家可以去参考它的[GitHub]. 这里先贴出GitHub上提供的效果图: 要使用这个框架,我们需要首先导入它的依赖: compile 'com ...

  9. 未能正确加载“visual C++ package”包

    早上打开360要卸载软件,跳出说系统修复,习惯性的点击修复,结果修复后发现打开vs2012提示“未能正确加载“visual C++ package”包……..”, 重启也一样,google了下,是因为 ...

  10. 淘宝分布式数据层:TDDL[转]

    淘宝根据自己的业务特点开发了TDDL(Taobao Distributed Data Layer 外号:头都大了 ©_Ob)框架,主要解决了分库分表对应用的透明化以及异构数据库之间的数据复制,它是一个 ...