type studio inputtype edittext android android-studio android-edittext keyboard

android - studio - ¿Cómo ocultar el teclado con un toque fuera de un texto de edición?



keyboard android studio (1)

Intenta reemplazar onTouch con onTouch . Para esto, necesita cambiar sus atributos de diseño de esta manera:

<RelativeLayout android:id="@+id/relativeLayout" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true"> <RelativeLayout> // widgets here </RelativeLayout> </RelativeLayout>

A continuación, elimine el rl_main_onClick(View view) {...} e inserte el método de escucha onTouch dentro de onCreate() :

findViewById(R.id.relativeLayout).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); return true; } });

Quiero ocultar el teclado tocando afuera del texto de edición. Este es mi código xml:

<RelativeLayout android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" android:onClick="rl_main_onClick"> <RelativeLayout //Here there are some widgets including some edittext. </RelativeLayout>

Este es mi código Java (MainActivity):

public void rl_main_onClick(View view) { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); }

Pero tengo que tocar dos veces para ocultar el teclado. El primer toque simplemente cambia "next" (para el último edittext está "hecho") para ingresar el ícono, luego el segundo toque oculta el teclado. Esto es lo que sucede con el primer toque:

Ahora tengo dos preguntas:

1- ¿Cómo puedo arreglarlo y ocultar el teclado con solo un toque?

2- ¿Es posible hacerlo para todo mi texto de edición (un código para todos)?

Gracias por adelantado.