material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

[MaterialTimePicker] Keyboard re-appears after closing dialog #1956

Open adrcotfas opened 3 years ago

adrcotfas commented 3 years ago

Description: Using the MaterialTimePicker dialog with _INPUT_MODEKEYBOARD and pressing either positive or negative button will cause the keyboard to re-appear (but alphanumeric, not with digits).

This does not occur when dismissing the dialog by clicking outside of it, only when pressing Cancel or OK while the digits keyboard is open.

https://user-images.githubusercontent.com/11249107/103244036-5fef2f00-4964-11eb-8450-419db5ee3ed1.mp4

Maybe the following is related:

2020-12-28 23:17:48.041 1291-1291/com.google.android.inputmethod.latin E/KeyboardViewController: KeyboardViewController.show():438 Requesting to show sub view with id 2131428318(key_pos_password_header_numbers) which doesn't exist in current keyboard view
    jyl
        at klb.a(PG:195)
        at bty.a(PG:4)
        at com.google.android.apps.inputmethod.latin.keyboard.LatinPasswordKeyboard.a(PG:19)
        at kfh.a(PG:15)
        at kev.a(PG:31)
        at kev.H(PG:26)
        at kez.d(PG:10)
        at kez.b(PG:108)
        at com.android.inputmethod.latin.LatinIME.b(PG:339)
        at dwq.onStartInputView(PG:786)
        at android.inputmethodservice.InputMethodService.doStartInput(InputMethodService.java:2339)
        at android.inputmethodservice.InputMethodService$InputMethodImpl.startInput(InputMethodService.java:620)
        at android.inputmethodservice.InputMethodService$InputMethodImpl.dispatchStartInputWithToken(InputMethodService.java:649)
        at android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java:199)
        at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:44)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Expected behavior: The keyboard does not re-open after closing the dialog.

Source code:

            val dialog = MaterialTimePicker.Builder()
                    .setHour(time.hour)
                    .setMinute(time.minute)
                    .setTimeFormat(if (is24HourFormat) TimeFormat.CLOCK_24H else TimeFormat.CLOCK_12H)
                    .setInputMode(INPUT_MODE_KEYBOARD)
                    .build()
            dialog.show(parentFragmentManager, "MaterialTimePicker")

Android API version: 26 and 30

Material Library version: 1.3.0-alpha03

Device: Emulator Nexus 4 API 30 and Samsung SM-A320FL API level 26

agustinsivoplas commented 2 years ago

Any solution or workaround for this?

1fish2 commented 2 years ago

The obvious workaround approach would be a "dismiss" listener which hides the soft keyboard, but hiding the keyboard is an unsolved problem: https://stackoverflow.com/q/1109022/1682419

Of the 142 answers on SO, the ones I tried didn't work. There's a combination lock on the keyboard, so you have to find the right View and get its window token?

paulfthomas commented 2 years ago

Is this issue still occurring in 1.6.0? I can't reproduce.

paulfthomas commented 2 years ago

It seems this issue has been resolved in https://github.com/material-components/material-components-android/commit/5d6678cc66e64c379818bc294a3db4a19e1005a4, closing.

Mori-hub commented 1 year ago

val view: View? = this.currentFocus

        // on below line checking if view is not null.
        if (view != null) {
            // on below line we are creating a variable
            // for input manager and initializing it.
            val inputMethodManager =
                getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager

            // on below line hiding our keyboard.
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0)
lwasyl commented 1 year ago

https://github.com/material-components/material-components-android/issues/1956#issuecomment-1129335435

It doesn't seem resolved in 1.9.0, yes the keyboard gets hidden when the mode is changed (like the commit message says), but when the user dismisses the dialog in any way the keyboard appears again, just like on the video from original message

evgenyvalavin commented 1 year ago

https://github.com/material-components/material-components-android/issues/1956#issuecomment-1129335435

It doesn't seem resolved in 1.9.0, yes the keyboard gets hidden when the mode is changed (like the commit message says), but when the user dismisses the dialog in any way the keyboard appears again, just like on the video from original message

Same for me. Keyboard re-appears when a MaterialAlertDialog is dismissed

agustinsivoplas commented 1 year ago

A workaround that worked for me was add stateAlwaysHidden in windowSoftInputMode

<activity
            android:name=".features.main.MainActivity"
            android:windowSoftInputMode="adjustResize|stateAlwaysHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>