android 数字键盘制作
//布局相关
<?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 数字键盘制作的更多相关文章
- pjsip视频通信开发(上层应用)之数字键盘的制作
在pjsip视频通信开发(上层应用)之EditText重写中我制作了一个显示输入内容的EditText,这里将制作一个数字键盘,其实跟计算器一样,最多的就是用TableLayout来实现,内部通过权重 ...
- 【笔记】移动端H5数字键盘input type=number的处理(IOS和Android)
在Vue中的项目,基于VUX-UI开发,一个常见的需求: 1.金额输入框 2.弹出数字键盘 3.仅支持输入两位小数,限制最大11位数,不允许0开头 后续:与UI沟通后, 思路调整为限制输入,并减少正则 ...
- 手机端访问web调用数字键盘。
转自 http://www.webkfa.com/one4/w1937.html 最近在做手机页面时,遇到数字输入的键盘的问题,之前的做法只是一刀切的使用 type="tel", ...
- js Date 函数方法 和 移动端数字键盘调用
var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-???? ...
- Android自定义键盘
布局文件 <?xml version="1.0" encoding="UTF-8"?> <Keyboard android:keyWidth= ...
- [HTML5]移动开发不同手机弹出数字键盘问题
这里还是先那么先交代一下遇到的问题.其实无论是tel还是number都不是完美的:type="tel"优点是iOS和Android的键盘表现都差不多缺点是那些字母好多余,虽然我没有 ...
- SenchaTouch调用纯数字键盘
items:[ { itemId:"phoneNumber", xtype: "textfield", component:{xtype:"input ...
- 一个数字键盘引发的血案——移动端H5输入框、光标、数字键盘全假套件实现
https://juejin.im/post/5a44c5eef265da432d2868f6 为啥要写假键盘? 还是输入框.光标全假的假键盘? 手机自带的不用非得写个假的,吃饱没事干吧? 装逼?炫技 ...
- input 弹起数字键盘的那些坑
input ios 踩的大坑 前言:最近有个需求要将全平台的交易密码由原来的 6-16位 复杂密码改为6位纯数字交易密码,涉及到非常多的业务场景,但修改起来也无非两种:设置交易密码,使用交易密码 设置 ...
随机推荐
- 微软HoloLens技术解谜
HoloLens 是什么? HoloLens 是微软发布的可穿戴式增强现实计算设备,它拥有这么几个关键要素: 它是增强现实产品,即 Augmented Reality(AR),AR 技术将计算机生成的 ...
- MockupBuilder
玩一下,想起了以前公司产品经理作的些事了...
- R语言 数据的输入方式总结
1.使用C函数连接数据 2.使用c,cbind,rbind结合变量 3.使用Vector函数结合数据 4.使用矩阵结合数据5.使用data.frame函数结合数据 6.使用list函数结合数据 c 向 ...
- 【狼】unity 鼠标拖拽物体实现任意角度自旋转
主要涉及函数 Input.GetAxis(“Mouse x”) 可取得鼠标横向(x轴)移动增量 Input.GetAxis(“Mouse y”) 可取得鼠标竖向(y轴)移动增量 通过勾股定理获取拖拽长 ...
- Hibernate(一)JDBC简介
在了解Hibernate之前,我们先回顾一下传统JDBC访问数据库的相关内容.重点在于分析JDBC访问存在哪些 缺陷,这些缺陷在Hibernate中是如何思考和解决的? JDBC主要对象 DriveM ...
- yarn的初步理解
查考site: http://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-site/YARN.html yarn结构图如下: 1.yar ...
- java---Unicode-字符转换器
实现一个字符(包括汉字)的简单互相转换: package cn.hncu.gui2; import java.awt.Button; import java.awt.Color; import jav ...
- Ural 1332 把圆细分+圆内切,内含关系判定
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1332 #include<cstdio> #include<cstrin ...
- lightoj 1018 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cst ...
- vim setting
django_百度搜索 最近合并代码,发现文件缩进经常不一致,请大家把以下配置放到自己主目录下.vimrc文件中. set tabstop=4 set shiftwidth=4 set e ...