小编Sol*_*n14的帖子

活动开始时为什么显示软键盘?

在比较开发人员之间的设计时,我们发现了一种奇怪的行为 经过一番分析后,我们进行了观察.

当活动开始时,在某些情况下会出现键盘但有时不会出现.

事实上,没有a ScrollView,软键盘默认不会出现在EditText.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TestActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10"
        android:inputType="text" >
        <requestFocus />
    </EditText>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但是当我们添加一个时ScrollView,默认情况下会出现软键盘.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TestActivity" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >
        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="text" >
            <requestFocus />
        </EditText>
    </ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

它只取决于存在ScrollView.我们可以使用特定声明修复它AndroidManifest,但这是默认行为.

我和我的同事们想知道为什么会这样?

user-interface android scrollview android-softkeyboard android-edittext

7
推荐指数
1
解决办法
2284
查看次数