mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
NumberPickerFactory: Show and hide keyboard using InputMethodManager
In about 1 every 10 attempts, the previous solution randomly failed to show the keyboard, although the text field was focused. This solution seems more reliable.
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.*
|
||||
import android.graphics.*
|
||||
import android.util.*
|
||||
import android.view.*
|
||||
import android.view.inputmethod.*
|
||||
import android.widget.*
|
||||
import android.widget.TextView.*
|
||||
import androidx.core.view.*
|
||||
@@ -82,4 +83,16 @@ object InterfaceUtils {
|
||||
return ViewCompat.getLayoutDirection(view!!) ==
|
||||
ViewCompat.LAYOUT_DIRECTION_RTL
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getInputManager() =
|
||||
this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
|
||||
fun Context.showKeyboard() {
|
||||
this.getInputManager().toggleSoftInput(InputMethodManager.SHOW_FORCED,
|
||||
InputMethodManager.HIDE_IMPLICIT_ONLY)
|
||||
}
|
||||
|
||||
fun Context.hideKeyboard() {
|
||||
this.getInputManager().toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
|
||||
}
|
||||
Reference in New Issue
Block a user