You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.1 KiB
30 lines
1.1 KiB
package com.gyf.csams.util
|
|
|
|
import android.app.Activity
|
|
import android.view.View
|
|
import android.view.inputmethod.InputMethodManager
|
|
import com.orhanobut.logger.Logger
|
|
|
|
object ContextUtil {
|
|
fun hideKeyBoard(activity: Activity?) {
|
|
Logger.i("隐藏软键盘")
|
|
activity?.apply {
|
|
val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
window.peekDecorView()?.let {
|
|
imm.hideSoftInputFromWindow(it.windowToken, 0)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun testHideKeyBoard(activity: Activity) {
|
|
Logger.i("隐藏软键盘")
|
|
val imm = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
//Find the currently focused view, so we can grab the correct window token from it.
|
|
var view: View? = activity.currentFocus
|
|
//If no view currently has focus, create a new one, just so we can grab a window token from it
|
|
if (view == null) {
|
|
view = View(activity)
|
|
}
|
|
imm.hideSoftInputFromWindow(view.windowToken, 0)
|
|
}
|
|
} |