6

I have an activity that has a SearchView directly above a ListView. The activity works by the user typing text in the SearchView which is then used to filter the content of the ListView.

On a 4" phone (Nexus 4) when the app is in "portrait" orientation and the user starts to input text in the search view, the lower half of the screen occupies the keyboard and the text is entered directly within the SearchView widget.

However, when the phone is in "landscape" orientation, the whole screen is occupied by the keyboard and a "text field" and the rest of the screen is lost. The "Search" button and the "Magnify glass" button on the keyboard seem to have no action.

See the screenshotsenter image description here

Question

Is it possible to have the text entered directly in the SearchView widget when in landscape orientation?

If not, how do I make the buttons on the keyboard do something?

BENBUN Coder
  • 4,801
  • 7
  • 52
  • 89
  • *Is it possible to have the text entered directly in the SearchView widget when in landscape orientation* - I don't think so. *how do I make the buttons on the keyboard do something?* - what buttons? what to do? – user Mar 08 '13 at 16:14
  • "The "Search" button and the "Magnify glass" button on the keyboard seem to have no action." – BENBUN Coder Mar 08 '13 at 16:18
  • Sorry about that, I've totally missed that sentence. Are you sure you don't get the `onQueryTextSubmit` call when clicking on either search or the magnify button? – user Mar 08 '13 at 16:37

3 Answers3

14

You need to set your imeOptions for the SearchView widget, for example in the SearchableInfo xml:

android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen"

Similar can be achieved via setImeOptions if your not using xml to configure your search view.

CCRoss
  • 141
  • 1
  • 3
2

Setting the imeOptions to an android.support.v7.widget.SearchView doesn't work: you'll need to set this at the EditText inside it:

Java:

EditText searchInput = searchview.findViewById(android.support.v7.appcompat.R.id.search_src_text)
searchInput.setImeOptions(EditorInfo.IME_ACTION_SEARCH)

Kotlin:

val searchInput = searchview.findViewById<EditText>(android.support.v7.appcompat.R.id.search_src_text)
searchInput.imeOptions = EditorInfo.IME_ACTION_SEARCH
Cristan
  • 12,083
  • 7
  • 65
  • 69
  • Can you please look at this question. I tried your solution but it didn't work in my case. https://stackoverflow.com/questions/46263084/android-search-tool-in-landscape-orientation – Abu Qatada Sep 17 '17 at 14:12
  • Using imeOptions in xml as in CCRoss answer in an android.support.v7.widget.SearchView works just fine for me. – Josh May 05 '19 at 11:05
0

You can do it from Java code like following, in onCreateOptionsMenu(Menu menu) method:

searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
Community
  • 1
  • 1
Mr. Oronno
  • 339
  • 4
  • 4