mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-21 03:02:59 -04:00
Fixes of toggleSoftInput(Int, Int) method of InputMethodManager is deprecated
This commit is contained in:
parent
66a535111c
commit
f5ba5f4cf0
@ -39,7 +39,7 @@ fun Fragment.toast(stringId: Int, length: Int = Toast.LENGTH_LONG) {
|
||||
fun Fragment.closeKeyboard() {
|
||||
val inputMethodManager =
|
||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
|
||||
inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
|
||||
}
|
||||
|
||||
fun View.closeKeyboard() {
|
||||
|
@ -32,6 +32,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
@ -289,15 +290,22 @@ class AddNoteDialog : DialogFragment() {
|
||||
)
|
||||
if (!noteFileExists) {
|
||||
// Prepare for input in case of empty/new note
|
||||
dialogNoteAddNoteBinding?.addNoteEditText?.requestFocus()
|
||||
showKeyboard()
|
||||
dialogNoteAddNoteBinding?.addNoteEditText?.apply {
|
||||
requestFocus()
|
||||
showKeyboard(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showKeyboard() {
|
||||
@Suppress("MagicNumber")
|
||||
private fun showKeyboard(editText: EditText) {
|
||||
val inputMethodManager =
|
||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
|
||||
editText.postDelayed(
|
||||
{
|
||||
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
|
||||
}, 100
|
||||
)
|
||||
}
|
||||
|
||||
private fun saveNote(noteText: String) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user