No se puede mostrar el teclado automáticamente en el SearchView
El SearchView está enfocado de forma predeterminada, pero cuando intento mostrar el teclado del software, no sucede:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Pero cuando hago clic en el SearchView – lo hace. ¿Por qué?
- Biblioteca de soporte de Android 24.0.0 no muestra texto en SearchView
- Android ActionBar: plegable SearchView con botón de acción
- Menu.findItem devuelve null
- Estilo AppCompat SearchView con AppCompat 22.1.0 no funciona
- Cómo utilizar onQueryTextChange con muchos fragmentos
- Expanda la vista de búsqueda para usar toda la barra de acciones (ocultar otras cosas)
- ¿Cómo detectar si SearchView se expande?
- Enviar una consulta cuando haga clic en el botón de búsqueda en el teclado
- Gire AutoCompleteTextView en un SearchView en ActionBar en su lugar
- SearchManager.getSearchableInfo (getComponentName ()) devuelve null
- Filtro de búsquedaVer ListView
- SearchView en OptionsMenu no es el ancho completo
- SearchView en ListView con un adaptador personalizado
¡Fijo!
mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { showInputMethod(view.findFocus()); } } });
Y
private void showInputMethod(View view) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.showSoftInput(view, 0); } }
Encontré este problema con un SearchView que todavía no abriría el teclado, y podía hacerlo agregando un retardo de 200ms:
mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(final View view, boolean hasFocus) { if (hasFocus) { view.postDelayed(new Runnable() { @Override public void run() { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(view.findFocus(), 0); } }, 200); } } });
¿Qué pasa con setOnFocusChangeListener
?
searchview.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus){ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); } } });
Si está utilizando SearchView :
<android.support.v7.widget.SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="wrap_content" android:focusableInTouchMode="true" android:iconifiedByDefault="true" app:showAsAction="always" app:iconifiedByDefault="true"/>
A continuación, sólo tiene que añadirlo a su método onCreate :
final SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); searchView.setFocusable(true); searchView.setIconified(false); searchView.requestFocusFromTouch();
Esto funciona para mi.
Resolví este problema de la siguiente manera simple.
Elemento de menú SearchView:
<item android:id="@+id/menu_item_search" android:icon="@drawable/ic_search" android:title="@android:string/search_go" app:actionViewClass="android.support.v7.widget.SearchView" app:showAsAction="**always|collapseActionView**" />
Para expandir SearchView y mostrar el teclado mediante programación, llame al:
mMenuItemSearch.expandActionView(); mSearchView.setQuery("your default query test or null", true);
Probado con diferentes banderas showAsAction. Como resultado el teclado no se muestra cuando el indicador: " siempre ". Sin embargo, todo funciona con flag: " always | collapseActionView "
ExpandActionView () + setQuery ("texto nulo o restaurado", true); Puede ser llamado cuando la vista creada (o restaurada) muestre el teclado y se enfoque en la búsqueda. PS: llama a mSearchView.clearFocus (); Después de estos dos métodos si no necesita el foco de búsqueda.
Tratar:
void focusSearchViewAndOpenOrCloseKeyboard(boolean focus) { searchView.setIconified(focus); }
La fuente nos muestra que SearchView
maneja su propio cierre y apertura del teclado virtual .
- ¿Cómo saber si una aplicación de Android está realmente goteando memoria?
- ¿Es posible utilizar un dispositivo para ejecutar una aplicación exclusivamente?