Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: don't show soft keyboard automatically [duplicate]

I have following layout:

<LinearLayout
    android:id="@+id/linearLayoutHolder"
    android:layout_alignParentBottom="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_vertical"
    android:background="@android:color/white" >

    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:inputType="textCapSentences"
        android:background="@android:color/transparent"
        android:hint="@string/edit_message"
        android:textColorHint="@android:color/darker_gray"
        android:windowSoftInputMode="stateHidden"/>

</LinearLayout>

This produces:

enter image description here

Now, when user presses the show background apps button at the bottom (as shown in above picture), and when user comes back to the app, the soft keyboard gets shown.

enter image description here

I don't want the soft keyboard to be shown in this case.

How can this be done?

like image 203
user5155835 Avatar asked Feb 05 '26 12:02

user5155835


1 Answers

In your AndroidManifest.xml, add the below attribute for the entry of this Activity:

android:windowSoftInputMode="stateHidden"

It is not supposed to be written in your layout XML, but the AndroidManifest.xml.

To set more than one soft input modes, you can set it like:

android:windowSoftInputMode="stateHidden|adjustResize"

For more information, you can refer the documentation.

like image 158
Kamran Ahmed Avatar answered Feb 07 '26 04:02

Kamran Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!