zoukankan      html  css  js  c++  java
  • android键盘的Done按钮

    在EditText中,可以使用setImeOptions()方法来来开启软键盘的"Done"按钮。
    示例代码如下:editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

     按下"Done"按钮的默认行为是关闭软键盘,但是我们可以通过EditTextsetOnEditorActionListener()方法来设置OnEditorActionListener以便添加自己的行为.

    捕获Android文本输入框的软键盘完成(Done)按键消息:
        editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {  
          
            @Override  
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {  
                if (actionId == EditorInfo.IME_ACTION_DONE) {  
                    InputMethodManager imm = (InputMethodManager)v.getContext()
    .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(),
    0); doSomething(); return true; } return false; } });

    EditorInfo.IME_ACTION_DONE可以和其他的标志一起组合使用来设置软键盘,比如:
    editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI|EditorInfo.IME_ACTION_DONE); 
    注意1EditorInfo.IME_ACTION_DONE只有对android:singleLine="true"的EditText有效。至少对HTC_A9191是这样的。
    注意2:对于EditorInfo.IME_ACTION_DONE,有些输入法并不支持它,比如搜狐拼音输入法。
  • 相关阅读:
    jQuery知识总结
    WEB架构师成长之路之2
    利用Travis CI 让你的github项目持续构建(Node.js为例)
    C#实现UDP分包组包
    win7下安装32位GoSublime Package
    爬虫部分技术要点浅析
    如何使用“依赖注入”的
    分布式ACM Online Judge 架构设计
    “容器组件服务”模型
    Maven学习
  • 原文地址:https://www.cnblogs.com/maxiaodoubao/p/3165853.html
Copyright © 2011-2022 走看看