material-components / material-components/material-components-android

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

Open
#4,518 0 comments 0 reactions 1 assignee View on GitHub

@hunterstich is already working on this.

Since Jan 2, 2025.

bug Widget: Search
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**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](https://github.com/user-attachments/assets/f71cd6cc-5e9b-4a57-9d98-887910db9601)

**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
```

```

**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](https://github.com/user-attachments/files/18283834/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.