开发者

Soft-keyboard appears every time layout becomes visible

开发者 https://www.devze.com 2023-04-11 19:58 出处:网络
I have two layouts within a fragment that I switch back and forth between by making one invisible and the other visible and visa versa.When the layout that contains an EditText becomes visible the sof

I have two layouts within a fragment that I switch back and forth between by making one invisible and the other visible and visa versa. When the layout that contains an EditText becomes visible the soft keyboard automatically pops up. I have used the following in the manifest but it didn't help.

android:windowSoftInputMode="stateUnchanged"

I never explicitly request focus on the EditText and have even tried requesting focus on something else to no avail.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:id="@+id/container">
    <LinearLayout android:id="@+id/dial_pad_ll"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:orientation="vertical" android:layout_centerInParent="true"
        android:background="#1E1E1E" android:layout_marginLeft="20dp" android:layout_marginRight="20dp">
        <EditText android:layout_height="wrap_content" android:id="@+id/search_et"
            android:layout_width="match_parent" android:layout_alignParentTop="true"
            android:layout_marginTop="20dp" android:layout_margi开发者_运维问答nBottom="10dp" >
        </EditText>
        <!-- Other widgets here -->
    </LinearLayout>
    <!-- Other Layout Here -->
</RelativeLayout>

Anyone know how to prevent this? Thanks.

Edit: I should also have mentioned that this doesn't happen the first time. I open layout 1 with the edit text, make it invisible, make it visible again, then the keyboard pops up.


try adding this to your activity.

this.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号