【问题标题】:How to make "Done" button close keyboard [duplicate]如何使“完成”按钮关闭键盘[重复]
【发布时间】:2014-08-22 16:56:43
【问题描述】:

我需要帮助,以便当您打开键盘时,“完成”按钮将关闭键盘。附言我已经有了它,所以键盘上有“完成”按钮。谢谢!

【问题讨论】:

  • 您使用的是UITextFieldUITextView,还是其他?
  • 另外,这是 iOS 还是 OSX?

标签: objective-c button keyboard


【解决方案1】:

对于 iOS 使用 resignFirstResponder

[textView resignFirstResponder]
[textField resignFirstResponder]

【讨论】:

    【解决方案2】:

    你应该在你的编辑中添加一个监听器:

    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId== EditorInfo.IME_ACTION_DONE){
                // Dismiss the keyboard here.
                return true;
            }
            return false;
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 2021-01-30
      • 2019-02-18
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      相关资源
      最近更新 更多