mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 20:54:13 -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() {
|
fun Fragment.closeKeyboard() {
|
||||||
val inputMethodManager =
|
val inputMethodManager =
|
||||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0)
|
inputMethodManager.hideSoftInputFromWindow(requireView().windowToken, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.closeKeyboard() {
|
fun View.closeKeyboard() {
|
||||||
|
@ -32,6 +32,7 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import android.widget.EditText
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
@ -289,15 +290,22 @@ class AddNoteDialog : DialogFragment() {
|
|||||||
)
|
)
|
||||||
if (!noteFileExists) {
|
if (!noteFileExists) {
|
||||||
// Prepare for input in case of empty/new note
|
// Prepare for input in case of empty/new note
|
||||||
dialogNoteAddNoteBinding?.addNoteEditText?.requestFocus()
|
dialogNoteAddNoteBinding?.addNoteEditText?.apply {
|
||||||
showKeyboard()
|
requestFocus()
|
||||||
|
showKeyboard(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showKeyboard() {
|
@Suppress("MagicNumber")
|
||||||
|
private fun showKeyboard(editText: EditText) {
|
||||||
val inputMethodManager =
|
val inputMethodManager =
|
||||||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as 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) {
|
private fun saveNote(noteText: String) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user