Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SearchView] when the SearchView is collapsed, the soft keyboard would appear when typing #4518

Open
AndroidDeveloperLB opened this issue Dec 31, 2024 · 0 comments
Assignees

Comments

@AndroidDeveloperLB
Copy link

AndroidDeveloperLB commented Dec 31, 2024

Description: Full description of issue here

  1. Have a SearchView used in the app. Either run via a mirrored way (using ScrCpy or the IDE), or run on emulator
  2. Try to type using the PC's keyboard right on beginning. Nothing occurs, as it should
  3. Open the SearchView, and then type. The soft keyboard appears as soon as you open the SearchView (as it should). You might see other issues such as the keyboard going away for some reason (bug!).
  4. Now close the SearchView, notice the soft-keyboard also goes away.
  5. Again type.

The bug is that the soft-keyboard appears again, as if you can type...

image

Expected behavior: Screenshots and/or description of expected behavior
The keyboard should stay when I can type to something (and shouldn't close by itself), and it shouldn't appear when I start typing into nothing.

Source code: The code snippet which is causing this issue

override fun onCreateOptionsMenu(menu: Menu): Boolean {
    // Inflate the menu; this adds items to the action bar if it is present.
    menuInflater.inflate(R.menu.menu_main, menu)
    menu.findItem(R.id.menuItem_search)
        .setOnActionExpandListener(object : OnActionExpandListener {
            override fun onMenuItemActionExpand(item: MenuItem): Boolean {
                Log.d("AppLog", "onMenuItemActionExpand")
                return true
            }

            override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
                Log.d("AppLog", "onMenuItemActionCollapse")
                return true
            }
        })
    return true
}

res/menu/menu_main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.lb.myapplication.MainActivity">

    <item
        android:id="@+id/menuItem_search"
        android:icon="@android:drawable/ic_search_category_default" android:title="search"
        app:actionViewClass="androidx.appcompat.widget.SearchView"
        app:showAsAction="always|collapseActionView" />

    <item
        android:id="@+id/action_settings" android:orderInCategory="100"
        android:title="@string/action_settings" app:showAsAction="never" />
</menu>

Minimal sample app repro: Please consider attaching a minimal sample app that reproduces the issue. This will help narrow down the conditions required for reproducing the issue, and it will speed up the bug fix process. You may attach a zip file of the sample app or link to a GitHub repo that contains the sample app.

Attached, together with a video:

MyApplication.zip

Android API version: Android API version here
35 (Android 15)

Material Library version: Material Android Library version you are using here (e.g., 1.1.0-alpha07)

    implementation("androidx.core:core-ktx:1.16.0-alpha01")
    implementation("com.google.android.material:material:1.13.0-alpha09")
    implementation("androidx.constraintlayout:constraintlayout:2.2.0")
    implementation("androidx.navigation:navigation-fragment-ktx:2.8.5")
    implementation("androidx.navigation:navigation-ui-ktx:2.8.5")

Device: Device on which the bug was encountered here
Pixel 6 and emulator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants