首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在安卓系统中输入EditText后如何隐藏键盘?

在安卓系统中输入EditText后如何隐藏键盘?
EN

Stack Overflow用户
提问于 2010-02-26 23:22:41
回答 15查看 165.7K关注 0票数 74

我有一个EditText和按钮对齐到家长的底部。

当我在其中输入文本并按下按钮保存数据时,虚拟键盘不会消失。

有谁能教我怎么隐藏键盘吗?

EN

回答 15

Stack Overflow用户

回答已采纳

发布于 2010-02-26 23:56:53

这应该是可行的。

代码语言:javascript
复制
InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS); 

只需确保this.getCurrentFocus()不返回null,如果没有任何对象具有焦点,它就会返回null。

票数 132
EN

Stack Overflow用户

发布于 2012-04-17 09:58:35

您可能还想在EditText中定义imeOptions。这样,一旦按下Done,键盘就会消失:

代码语言:javascript
复制
<EditText
    android:id="@+id/editText1"
    android:inputType="text"
    android:imeOptions="actionDone"/>
票数 142
EN

Stack Overflow用户

发布于 2015-10-26 15:03:34

代码语言:javascript
复制
   mEtNumber.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // do something, e.g. set your TextView here via .setText()
                    InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                    return true;
                }
                return false;
            }
        });

和xml格式

代码语言:javascript
复制
  android:imeOptions="actionDone"
票数 26
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2342620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档