Hide Keyboard when sending message

Asked

Viewed 70 times

0

Hello, then.. I’m looking for a solution for when the user sends the message the keyboard closes automatically. Thanks in advance.

<Button

    android:id="@+id/singleComentBtn"
    android:layout_width="80dp"
    android:layout_height="40dp"
    android:background="@drawable/btnchat"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginBottom="4dp"/>

<EditText
    android:id="@+id/singleBlogComent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/retangulo"
    android:layout_marginBottom="4dp"
    android:layout_marginLeft="3dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_toStartOf="@+id/singleComentBtn"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/singleComentBtn"
    android:layout_alignTop="@+id/singleComentBtn"
    />

1 answer

1

That’s probably what you’re looking for, this snippet of code forces Android to hide the keyboard,

View view = this.getCurrentFocus();
if (view != null) {  
   InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
   imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

This way depending on the occasion can happen that the keyboard is hidden without you want, so you can replace the second parameter of the method hideSoftInputFromWindow for InputMethodManager.HIDE_IMPLICIT_ONLY

Source:Hide Android Soft Keyboard

Browser other questions tagged

You are not signed in. Login or sign up in order to post.