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位纯数字交易密码,涉及到非常多的业务场景,但修改起来也无非两种:设置交易密码,使用交易密码 设置 ...
随机推荐
- 【POJ11855】 Buzzwords (后缀数组)
Description The word “the” is the most commonthree-letter word. It evenshows up inside other words, ...
- java基础随笔-内部类
今天来复习下内部类的一些基础知识. 首先是内部类的分类: 1.成员内部类 2.静态内部类 3.匿名内部类 4.局部内部类 下面逐一来介绍下. 首先是成员内部类,就是将内部类作为一个成员变量来处理.具体 ...
- perl 获取虚拟机信息
[root@master ~]# cat simple_flow.pl ! /usr/bin/perl -w use strict; use warnings; 导入 vSphere SDK for ...
- .net framework client profile
.NET Framework Client Profile The .NET Client Profile is a subset of the .NET Framework, which was p ...
- UC全屏
UC浏览器U3内核扩展接口定义
- IIS的ISAPI接口简介
ISAPI(Internet Server Application Programming Interface)作为一种可用来替代CGI的方法,是由微软和Process软件公司联合提出的Web服务 ...
- CSU 1505 酷酷的单词 湖南省赛第十届题目
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1505 题意:技巧题,就是一行字符串中,每个字母出现的次数互不相同,复即为酷的单词. 解题 ...
- java多线程编程(1) 线程的基本知识
在前面研究过多线程与进程的区别. 这里在稍微总结一下: 进程:程序动态的一次执行过程. 线程:可以只是程序员的一部分的执行过程 每个进程有多个线程组成,在java程序中,至少两个线程一个是垃圾回收线程 ...
- 《Numerical Methods》-chaper7-解线性方程组的直接方法和最小二乘问题
基于我们在线性代数中学习过的知识,我们知道解线性方程组本质上就是Gauss消元,也就是基于增广矩阵A的矩阵初等变换.关于数学层面的内容这里不做过多的介绍,这里的侧重点是从数值计算的角度来看这些常见的问 ...
- hdu 2066 一个人的旅行(最短路问题)
最短路································· 类似的问题还有好多不会!慢慢学吧!!!!. 进步,哪怕每天一点也行! (恋爱不是小事,确实小事的积累!(听着酷狗音乐台说的,很 ...