Android 软键盘功能键(EditText)
夜深了、废话不多说了,项目需要改变Android软键盘右角下的功能键!
好了!先看图?还是代码?.... 还是先代码、然后效果图!
代码:
public class MainActivity extends Activity {EditText editText1, editText2, editText3, editText4;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);init();property();}/*** 获取ID 事件*/private void init() {editText1 = (EditText) findViewById(R.id.editText1);editText2 = (EditText) findViewById(R.id.editText2);editText3 = (EditText) findViewById(R.id.editText3);editText4 = (EditText) findViewById(R.id.editText4);editText1.setOnEditorActionListener(new getOnEditorActionListener());editText2.setOnEditorActionListener(new getOnEditorActionListener());editText3.setOnEditorActionListener(new getOnEditorActionListener());editText4.setOnEditorActionListener(new getOnEditorActionListener());}/*** 赋值样式(这里是java代码给、也可以xml布局给)*/private void property() {// 搜素editText1.setImeOptions(EditorInfo.IME_ACTION_SEARCH);editText1.setInputType(EditorInfo.TYPE_CLASS_TEXT);// 下一个editText2.setImeOptions(EditorInfo.IME_ACTION_NEXT);editText2.setInputType(EditorInfo.TYPE_CLASS_TEXT);// 发送editText3.setImeOptions(EditorInfo.IME_ACTION_SEND);editText3.setInputType(EditorInfo.TYPE_CLASS_TEXT);// 完成editText4.setImeOptions(EditorInfo.IME_ACTION_DONE);editText4.setInputType(EditorInfo.TYPE_CLASS_TEXT);}/*** 内部内 实现了 OnEditorActionListener接口* @author asus**/class getOnEditorActionListener implements OnEditorActionListener {@Overridepublic boolean onEditorAction(TextView v, int actionId, KeyEvent event) {switch (actionId) {//当然这里判断是用标识列 int(相匹配)//假如我把 “搜素”换成 int(3) 也是成立case EditorInfo.IME_ACTION_SEARCH:Toast.makeText(getApplicationContext(), "你点击了 搜素! 内容为:"+v.getText(), 3).show();break;case EditorInfo.IME_ACTION_NEXT:Toast.makeText(getApplicationContext(), "你点击了 下一个! 内容为:"+v.getText(), 3).show();break;case EditorInfo.IME_ACTION_SEND:Toast.makeText(getApplicationContext(), "你点击了 发送! 内容为:"+v.getText(), 3).show();break;case EditorInfo.IME_ACTION_DONE:Toast.makeText(getApplicationContext(), "你点击了 完成! 内容为:"+v.getText(), 3).show();break;default:break;}return false;}}
主要代码:
public abstract boolean onEditorAction (TextView v, int actionId, KeyEvent event){}
参数
v | 执行动作的视图 |
---|---|
actionId |
动作标识. 该值可以是当回车键按下,调用该函数时你指定的值, 或者 EditorInfo.IME_NULL .
|
event | 如果由回车键触发,这是其事件;否则为空. |
返回值
- 如果你处理了该事件,返回真;否则返回假。
布局不贴、稍后提供源码下载!
效果图:
1.搜素
2.下一个
3.发送
4.确定
******************************************************
(扩展)
1.Android软键盘 显示
一般情况只有获得焦点,然后在调用系统软键盘
获得焦点:
editText1.requestFocus();
弹出软键盘:(开启一个定时器,弹出软键盘,前提要获得焦点!)
// 设置定时器(A跳到B页面,在B页面定时出现键盘,当然如果你是单一事件就不用、前提一定要获得焦点)Timer timer = new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {// 弹出软键盘的代码InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);imm.showSoftInput(editText1, InputMethodManager.RESULT_SHOWN);imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);}}, 10);//定义出现时间值
2.Android软键盘 关闭
// 关闭软键盘InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);imm.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
以上源代码:点击打开链接
转载请附出处:http://blog.csdn.net/cs_li1126/article/details/12630433
关于EditText属性 可以参考:
①:点击打开链接
②:点击打开链接
附:
软键盘的Enter键默认显示的是“完成”文本,通过设置android:imeOptions来改变默认的“完成”文本。这里举几个常用的常量值:actionUnspecified 未指定,对应常量EditorInfo.IME_ACTION_UNSPECIFIED.
actionNone 没有动作,对应常量EditorInfo.IME_ACTION_NONE
actionGo 去往,对应常量EditorInfo.IME_ACTION_GO
actionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH
actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND
actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT
actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE
Android 软键盘功能键(EditText)相关推荐
- Android软键盘遮挡EditText问题
最近在调试App过程遇到软件盘遮挡EditText的问题,特记录下问题的解决过程 在4.4版本上,如果EditText设置了gravity="center|right"其中之一且同 ...
- Android软键盘手动显示、隐藏、布局上移和EditText上移
主要实现:Android软键盘手动显示.隐藏.布局上移和EditText上移 AndroidManifest.xml <?xml version="1.0" encoding ...
- Android软键盘隐藏,遮挡EidtText解决办法
一.自动弹出软键盘 Timer timer=new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodM ...
- android软键盘enter键
enter键,回车键,电脑键盘上enter键就有多种响应.android软键盘也不例外 你在EditText上输入以后,想在下一行输入框输入,可能需要去点击下一行输入框,让它获取焦点,也可能要隐藏软键 ...
- android软键盘上添加一个按钮
android软键盘上添加一个按钮: 第一种 我们在根布局的最底部添加一个按钮,利用布局中的ScrollView在软键盘弹出的时候 将底部的按钮挤压到软键盘上边,先看效果图: 看代码: <?xm ...
- Android软键盘工具类
Android软键盘工具类 public class SoftKeyboardUtils {/*** 隐藏或显示软键盘* 如果现在是显示调用后则隐藏 反之则显示*/public static void ...
- Android软键盘弹出和收起的监听
Android软键盘弹出和收起的监听 1.直接调用 SoftKeyboardHelper softKeyboardHelper = softKeyboardHelper = new SoftKeybo ...
- Android软键盘的全面解析,让你不再怕控件被遮盖
本文转载自:https://blog.csdn.net/l540675759/article/details/74528641 背景 1.Android软键盘这块从我入职到现在,是一个一直纠缠我的问题 ...
- Android 软键盘 弹出,默认隐藏,强制隐藏,自动变大写等
经常时不时的需要控制软键盘的不同状态,每次用每次查,自己总结一下所有关于Android软键盘的东西写一块. 1.代码中弹出/隐藏软键盘: //view为接受软键盘输入的视图,SHOW_FORCED表示 ...
最新文章
- UA OPTI512R 傅立叶光学导论14 Wiener-Khinchine定理,Rayleigh定理与矩定理
- drools7 (一、最简单的例子)
- 管理 Active Directory 所必需的工具或技术
- mysql cluster cge (commercial)_Mysql 产品分类和版本说明
- matlab求微分方程同届,Matlab学习——求解微分方程(组)
- 自信不疑的人不会做的15件事
- docker 中安装 mongodb
- 大数据_Spark框架_快速上手_word count 案例-功能实现---Spark工作笔记0007
- 开源地图编辑器 MarbleMap,支持Cocos2d-x坐标系
- from import
- 如何获取select中的value、text、index相关值 如何获取单选框中radio值 触发事件 radio 默认选中...
- zookeeper管理mysql_Mysql系列九:使用zookeeper管理远程Mycat配置文件、Mycat监控、Mycat数据迁移(扩容)...
- Cinema 4D* 中令人惊叹的体积效果
- Endnote导出GB/T 7714-2015 格式参考文献
- ubuntu等linux发行版声卡、网卡、显卡驱动问题解决
- OSChina 周六乱弹 ——劳动节仍然在劳动,情人节却没有情人。
- 解决 Elasticsearch 查询时 Fielddata is disabled on text fields by default 错误
- 新年贺卡php,幼儿新年贺卡内容 元旦贺卡图片手工制作
- mysql求回购率_用户行为分析——回购率、复购率(SQL、Python求解)
- html ace编辑器,Springboot 集成 Ace editor前端编辑器