“Android Java Close Clavier” Réponses codées

Fermer le clavier Android

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = 
        (InputMethodManager) activity.getSystemService(
            Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(
        activity.getCurrentFocus().getWindowToken(), 0);
}
Hina

Android Java Close Clavier

package org.geeksforgeeks.gfgHideKey
  
    import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod
    .InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
  
public class MainActivity
    extends AppCompatActivity {
    private TextView textViewResult;
    private EditText editTextInput;
  
    @Override
    protected void onCreate(
        Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
  
        textViewResult
            = findViewById(
                R.id.text_view_result);
        editTextInput
            = findViewById(
                R.id.edit_text_input);
    }
  
    public void setText(View v)
    {
        String newText
            = editTextInput
                  .getText()
                  .toString();
        textViewResult.setText(newText);
  
        closeKeyboard();
        editTextInput.setText("");
    }
  
    private void closeKeyboard()
    {
        // this will give us the view
        // which is currently focus
        // in this layout
        View view = this.getCurrentFocus();
  
        // if nothing is currently
        // focus then this will protect
        // the app from crash
        if (view != null) {
  
            // now assign the system
            // service to InputMethodManager
            InputMethodManager manager
                = (InputMethodManager)
                    getSystemService(
                        Context.INPUT_METHOD_SERVICE);
            manager
                .hideSoftInputFromWindow(
                    view.getWindowToken(), 0);
        }
    }
}
Narongdetch

Réponses similaires à “Android Java Close Clavier”

Questions similaires à “Android Java Close Clavier”

Plus de réponses similaires à “Android Java Close Clavier” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code