Hide Keyboard when sending message [duplicate]

0

Hello, then .. I am looking for a solution for when the user sends the message the keyboard close automatically.Thank you 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"
    />

    
asked by anonymous 09.03.2017 / 18:49

1 answer

1

That's probably what you're looking for, this piece 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);
}

In this way depending on the occasion it can happen that the keyboard is hidden without you wanting, so you can substitute the second parameter of method hideSoftInputFromWindow with InputMethodManager.HIDE_IMPLICIT_ONLY

Source: Hide Android Soft Keyboard

    
09.03.2017 / 19:08