3

Tengo un SearchView y cuando el usuario gira el dispositivo quiero que se muestre el teclado si estaba escribiendo pero no lo consigo, sólo se muestra en vertical y no en horizontal ¿Alguna idea?

Dentro del método onCreateOptionsMenu tengo puesto lo siguiente:

if (!TextUtils.isEmpty(searchQuery) && buscando) {
    searchItem.expandActionView();
    searchView.setQuery(searchQuery, false); //Al poner true se cierra la aplicación
    searchView.setFocusable(true);
}

1 respuesta 1

1

Si quieres mantener el mismo layout y evitar que se destruya y vuelva a recrearse añade esta línea a la activity en el Manifest.xml

<activity
    ...
    android:configChanges="keyboardHidden|orientation|screenSize"
    .../>
        ...
</activity>

Deberías poder cambiar de orientación y mantener el teclado activo

Documentación:

https://developer.android.com/guide/topics/resources/runtime-changes.html

For example, the following manifest code declares an activity that handles both the screen orientation change and keyboard availability change:

Now, when one of these configurations change, MyActivity does not restart. Instead, the MyActivity receives a call to onConfigurationChanged(). This method is passed a Configuration object that specifies the new device configuration. By reading fields in the Configuration, you can determine the new configuration and make appropriate changes by updating the resources used in your interface. At the time this method is called, your activity's Resources object is updated to return resources based on the new configuration, so you can easily reset elements of your UI without the system restarting your activity.

Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.