1

My app worked fine for lots of devices. But since upgrading to Android 12 on my own Pixel the following happens when calling showSoftInput or just when tapping the AppCompatEditText in a Bottomsheet.

val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager;
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)

Logcat warning (nothing happens in the app):

Ignoring showSoftInput() as view=androidx.appcompat.widget.AppCompatEditText{b5311a0 VFED..CL. .F.P..ID 84,0-996,118 #7f0900a7 app:id/et_bottomsheet aid=1073741827} is not served.

I tried lots of things like requesting focus, showSoftInput with SHOW_FORCE but nothing worked.

Merthan Erdem
  • 5,598
  • 2
  • 22
  • 29

2 Answers2

3

Starting from Android 11 (API 30) you can manually force the ime/keyboard to show with inset's API show()

myAppCompatEditText.windowInsetsController.show(WindowInsetsCompat.Type.ime())

And hide it with:

myAppCompatEditText.windowInsetsController.hide(WindowInsetsCompat.Type.ime())

To targed APIs below API 30, This is backported using the Compat version:

WindowInsetsControllerCompat(window, myAppCompatEditText)
                                     .show(WindowInsetsCompat.Type.ime())

WindowInsetsControllerCompat(window, myAppCompatEditText)
                                     .hide(WindowInsetsCompat.Type.ime())
Zain
  • 37,492
  • 7
  • 60
  • 84
  • 1
    Thanks, will try this later. Won't fix the issue of the keyboard not getting shown when the EditText is clicked though unfortunately (might have to mess around with onTouch, Text focus etc) and then call this manually if nothing else works. – Merthan Erdem Feb 17 '23 at 09:22
1

Solution: The problem seems to be that the keyboard couldn't gain window focus?

Anyways, the parts that were causing problems were:

window?.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)

window?.decorView?.systemUiVisibility = fullscreenFlags

and

private const val fullscreenFlags = (View.SYSTEM_UI_FLAG_FULLSCREEN
        or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        or View.SYSTEM_UI_FLAG_IMMERSIVE
        or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)

I removed them for now on SDK 33+, which kind of breaks the hiding of navigation elements that I had before but it's the only way I could fix this quickly. Now everything seems to work.

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) doThose()
Merthan Erdem
  • 5,598
  • 2
  • 22
  • 29