Cómo ocultar Soft Keyboard cuando se inicia la actividad

Tengo un Edittext con android:windowSoftInputMode="stateVisible" en Manifest. Ahora el teclado se mostrará cuando inicie la actividad. ¿Cómo ocultarlo? No puedo usar android:windowSoftInputMode="stateHidden porque cuando el teclado es visible entonces minimizar la aplicación y reanudarla el teclado debe ser visible.

InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

Pero no funcionó.

Utilice las siguientes funciones para mostrar / ocultar el teclado:

 /** * Hides the soft keyboard */ public void hideSoftKeyboard() { if(getCurrentFocus()!=null) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } } /** * Shows the soft keyboard */ public void showSoftKeyboard(View view) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); view.requestFocus(); inputMethodManager.showSoftInput(view, 0); } 

En el archivo AndroidManifest.xml:

  <activity android:name="com.your.package.ActivityName" android:windowSoftInputMode="stateHidden" /> 

O intentar

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)‌​; 

Por favor, compruebe esto también

Simplemente agregue dos atributos a la vista principal de editText.

 android:focusable="true" android:focusableInTouchMode="true" 

Prueba esto:

 <activity ... android:windowSoftInputMode="stateHidden|adjustResize" ... > 

Mire este para más detalles.

Para ocultar el teclado de software en el momento de inicio de Nueva Actividad o onCreate() , onStart() etc., puede utilizar el código siguiente:

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

Poner esto en el manifiesto dentro de la etiqueta de actividad

  android:windowSoftInputMode="stateHidden" 

Agregue el siguiente texto a su archivo xml.

 <!--Dummy layout that gain focus --> <LinearLayout android:layout_width="0dp" android:layout_height="0dp" android:focusable="true" android:focusableInTouchMode="true" android:orientation="vertical" > </LinearLayout> 
  Try this one also Ed_Cat_Search=(EditText)findViewById(R.id.editText_Searc_Categories); Ed_Cat_Search.setInputType(InputType.TYPE_NULL); Ed_Cat_Search.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { Ed_Cat_Search.setInputType(InputType.TYPE_CLASS_TEXT); Ed_Cat_Search.onTouchEvent(event); // call native handler return true; // consume touch even } }); 

Ponga este código en su archivo java y pase el argumento para el objeto en edittext,

 private void setHideSoftKeyboard(EditText editText){ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); } 

Esto es lo que hice:

 yourEditText.setCursorVisible(false); //This code is used when you do not want the cursor to be visible at startup yourEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { v.onTouchEvent(event); // handle the event first InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); // hide the soft keyboard yourEditText.setCursorVisible(true); //This is to display cursor when upon onTouch of Edittext } return true; } }); 

Prueba esto.

En primer lugar en su xml de búsqueda los campos (nombre y pista etc) poner @string y no literal cadenas.

Entonces el método onCreateOptionsMenu , debe tener un objeto ComponentName con el nombre del paquete y el nombre completo de la clase (con el nombre del paquete) – En caso de que la actividad que tiene el componente SearchView es igual que los resultados de la búsqueda show use getComponentName() , como google android Desarrollador dice.

He probado muchas soluciones y después de mucho, mucho trabajo esta solución funciona para mí.

Espero que esto funcione, he intentado un montón de métodos, pero este trabajó para mí en fragments . Acaba de poner esta línea en onCreateview / init.

 getActivity().getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

Puedes configurar config en AndroidManifest.xml

Ejemplo:

 <activity android:name="Activity" android:configChanges="orientation|keyboardHidden" android:theme="@*android:style/Theme.NoTitleBar" android:launchMode="singleTop" android:windowSoftInputMode="stateHidden"/> 
  • Obtener la altura del teclado virtual en Android
  • Cómo incluir sugerencias en el teclado de Android
  • Ocultar el teclado de Android para EditText
  • ¿Por qué aparece el teclado virtual de Android cuando lo hace?
  • Android: cómo hacer que el teclado ingrese el botón diga "Buscar" y manejar su clic?
  • No quiero teclado suave para mostrar automáticamente en el lanzamiento - Android
  • Ocultación de la tarjeta de teclado de forma fiable
  • Teclado Android InputType sin EditText
  • Cómo ocultar el teclado virtual de Android en EditText
  • Indica cuándo se abre el teclado con "adjustNothing"
  • Mostrando el teclado sin animación
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.