Comment cacher le clavier souple lorsque l'activité commence
 j'ai un texte avec android:windowSoftInputMode="stateVisible"  dans le Manifeste. Maintenant, le clavier s'affichera lorsque je commencerai l'activité. Comment le cacher? Je ne peux pas utiliser  android:windowSoftInputMode="stateHidden  parce que lorsque le clavier est visible alors minimiser l'application et le reprendre le clavier devrait être visible. 
J'ai essayé avec  
  InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);   
mais ça n'a pas marché.
19 réponses
utilisez les fonctions suivantes pour afficher / masquer le clavier:
/**
 * 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);
}
  
    	                  dans le  AndroidManifest.xml :  
<activity android:name="com.your.package.ActivityName"
          android:windowSoftInputMode="stateHidden"  />
  
  ou d'essayer
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  
  s'il vous Plaît cochez la case ce aussi
il suffit d'ajouter deux attributs à la vue parent d'editText.
android:focusable="true"
android:focusableInTouchMode="true"
  
    	                mettez ceci dans le manifeste à l'intérieur de l'étiquette D'activité
  android:windowSoftInputMode="stateHidden"  
  
    	                 pour cacher le softkeyboard au moment du début de la nouvelle activité ou onCreate() , onStart()  etc. vous pouvez utiliser le code ci-dessous:  
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
    	                ajoutez le texte suivant à votre fichier 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>
  
    	                  j'espère que cela va fonctionner, j'ai essayé beaucoup de méthodes mais celle-ci a fonctionné pour moi dans  fragments  . il suffit de mettre cette ligne dans onCreateview/init.  
getActivity().getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
    	                vous pouvez définir config sur AndroidManifest.xml
exemple:
<activity
    android:name="Activity"
    android:configChanges="orientation|keyboardHidden"
    android:theme="@*android:style/Theme.NoTitleBar"
    android:launchMode="singleTop"
    android:windowSoftInputMode="stateHidden"/>
  
    	                pour masquer le softkeyboard au moment de la nouvelle activité start ou onCreate(),onStart() méthode etc. utilisez le code ci-dessous:
getActivity().getWindow().setSoftInputMode(WindowManager.
LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  
  pour cacher softkeyboard au moment du bouton est cliquez dans l'activité:
View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        assert imm != null;
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
  
    	                mettez ce code votre fichier java et passer l'argument pour l'objet sur edittext,
private void setHideSoftKeyboard(EditText editText){
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
  
    	                utilisez le code suivant pour cacher le softkeyboard première fois lorsque vous commencez l'activité
getActivity().getWindow().setSoftInputMode(WindowManager.
LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  
    	                C'est ce que j'ai fait:
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;
            }
        });
  
    	                essayez ceci.
 tout d'abord dans votre recherche xml les champs (Nom et indice, etc.) mettent @string  et non des chaînes littérales.  
 puis méthode onCreateOptionsMenu , il doit avoir un ComponentName objet avec votre nom de paquet et votre nom de classe complété (avec le nom de paquet) - au cas où l'activité qui a le composant SearchView est la même que l'utilisation des résultats de recherche de spectacle getComponentName() , comme le développeur android google dit.  
J'ai essayé beaucoup de solutions et d'après beaucoup,beaucoup de travail cette solution fonctionne pour moi.
essayez celui-ci aussi
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
    }
});
  
    	                si votre application cible API Android niveau 21 ou plus qu'il ya une méthode par défaut disponible.
editTextObj.setShowSoftInputOnFocus(false);
  
   assurez-vous d'avoir défini le code ci-dessous dans la balise XML EditText .  
<EditText  
    ....
    android:enabled="true"
    android:focusable="true" />
  
    	                Utilisant AndroidManifest.xml
<activity android:name=".YourActivityName"
      android:windowSoftInputMode="stateHidden"  
 />
  
  Utilisant Java
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  
  à l'aide de la solution ci-dessus clavier cacher mais édittext de se concentrer lorsque l'activité est créée, mais saisir lorsque vous les touchez en utilisant:
ajouter à votre EditText
<EditText
android:focusable="false" />
  
  ajouter aussi auditeur de votre texte électronique
youredittext.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
    v.setFocusable(true);
    v.setFocusableInTouchMode(true);
    return false;
}});
  
    	                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
    }
});
this one worked for me