Last active
August 16, 2020 11:17
-
-
Save Skyyo/a0436094ef0f7d87b884e45435d3d3c6 to your computer and use it in GitHub Desktop.
#extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.skyyo.ext | |
import android.app.Activity | |
import android.content.Context | |
import android.view.inputmethod.InputMethodManager | |
import androidx.fragment.app.Fragment | |
fun Fragment?.hideKeyboard() = | |
(this?.activity?.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager?)?.let { | |
if (it.isActive) it.hideSoftInputFromWindow(this@hideKeyboard?.view?.windowToken, 0) | |
} | |
fun Fragment?.showKeyboard() = | |
(this?.activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).toggleSoftInput( | |
InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment