LoginSignup
11

More than 5 years have passed since last update.

Androidでキーボードを閉じる方法メモ

Posted at

EditView などで文字列を入力後などに、キーボードを非表示にしたい場合の方法メモ。

class ContentFragment : Fragment() {

    private fun hideKeyboard() {
        val view = activity.currentFocus
        if (view != null) {
            val manager = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            manager.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }

}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11