1
votes

Cachez le clavier après avoir cliqué sur EditText

J'utilise le sélecteur de date et d'heure pour gérer le champ de date de la réunion, il n'est donc pas nécessaire d'utiliser le clavier. Comment puis-je empêcher le clavier de s'afficher après avoir cliqué sur le champ? entrez la description de l'image ici


0 commentaires

3 Réponses :


0
votes
val activity: Activity = this //if you are in the Activity
val imm = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
            var view = activity.currentFocus
            if (view == null) {
                view = View(activity)
            }
            imm.hideSoftInputFromWindow(view.windowToken, 0)
this piece of code should hide your virtual keyboard. Just put it in a method and call. :)

0 commentaires

0
votes

Vous pouvez utiliser la propriété android: focusableInTouchMode = "false" en xml

editText.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
       //show date picker
    }
});

Et ajouter un écouteur de clic à cette vue dans le code

<com.google.android.material.textfield.TextInputEditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusableInTouchMode="false"
    android:inputType="text|date"/>


0 commentaires

0
votes

Il existe un meilleur moyen de masquer le clavier par programme.

Allez en xml et ajoutez l'attribut suivant android:focusable="false"

Par exemple p >

<EditText
    android:id="@+id/time_date_et"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fontFamily="@font/prompt_light"
    android:focusable="false"
    android:textSize="17sp" />

L'attribut ci-dessus garantit que le clavier n'apparaîtra pas!


0 commentaires