SearchView and keyboard

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

On a 4-inch phone (Nexus 4), when the application is in โ€œportraitโ€ orientation, and the user starts typing in the search box, the bottom half of the screen is the keyboard, and the text is entered directly inside the SearchView Widget.

However, when the phone is in "landscape" orientation, the entire screen is occupied by the keyboard and the "text field", and the rest of the screen is lost. The Search button and the Zoom glass button on the keyboard have no effect.

See screenshots enter image description here

Question

Is it possible for the text to be entered directly into the SearchView widget in landscape orientation?

If not, how can I make the buttons on the keyboard?

+6
source share
3 answers

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

android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen" 

Similarly, this can be achieved with setImeOptions if you are not using xml to customize your search.

+12
source

Installing imeOptions in the android.support.v7.widget.SearchView file does not work: you need to set this to 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 
+2
source

You can do this using Java code, for example, in the onCreateOptionsMenu method (menu):

 searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN); 
0
source

All Articles