夜深了、废话不多说了,项目需要改变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 如果由回车键触发,这是其事件;否则为空.
返回值
  • 如果你处理了该事件,返回真;否则返回假。

没事还是多看看API文档吧、写的都很清楚@ : Android API(EditorInfo)



布局不贴、稍后提供源码下载!


效果图:


1.搜素

Android 软键盘功能键(EditText)_第1张图片


2.下一个

Android 软键盘功能键(EditText)_第2张图片


3.发送

Android 软键盘功能键(EditText)_第3张图片


4.确定

Android 软键盘功能键(EditText)_第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_GOactionSearch 搜索,对应常量EditorInfo.IME_ACTION_SEARCH    actionSend 发送,对应常量EditorInfo.IME_ACTION_SEND   actionNext 下一个,对应常量EditorInfo.IME_ACTION_NEXT   actionDone 完成,对应常量EditorInfo.IME_ACTION_DONE  











更多相关文章

  1. Android有用代码(一)
  2. Android PendingIntent实现原理和代码
  3. android Setting中隐藏项实现原理与代码
  4. Android Studio 单刷《第一行代码》系列 07 —— Broadcast 广播
  5. Android Studio 单刷《第一行代码》系列 06 —— Fragment 生命
  6. Android Studio 单刷《第一行代码》系列 01 —— 第一战 HelloWo

随机推荐

  1. Android(安卓)zip、tar+gz 压缩解压
  2. android density
  3. //转//Revisiting Android(安卓)disk enc
  4. Android(安卓)Code name Version API lev
  5. Android(安卓)侧滑删除功能
  6. Android生命周期实验
  7. Android(安卓)RSA 公钥加密、解密
  8. Android(Java):按钮复选框点中效果
  9. Android消息机制
  10. 图片压缩