接收焦点时 edittext 的奇怪行为
Strange behaviour of edittext when receiving focus
我有 2 个布局,其中包含 EditText 小部件。在第一个中,EditText 自动将焦点放在 activity 的开始处,但不显示任何软件键盘(这是所需的行为)。然而,在第二个布局中,EditText 聚焦 并且 显示软键盘。我检查了两种布局,但找不到这种行为的原因,因为这两种小部件具有相同的属性。仅当我触摸输入字段时才应显示软键盘。我错过了什么吗?
<EditText
android:id="@+id/scanLine"
android:layout_width="253.0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="19.0dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:inputType="text"
android:maxLines="1"
android:focusableInTouchMode="true" />
将以下行添加到 activity 的 onCreate()
方法中:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
希望对您有所帮助!
我有 2 个布局,其中包含 EditText 小部件。在第一个中,EditText 自动将焦点放在 activity 的开始处,但不显示任何软件键盘(这是所需的行为)。然而,在第二个布局中,EditText 聚焦 并且 显示软键盘。我检查了两种布局,但找不到这种行为的原因,因为这两种小部件具有相同的属性。仅当我触摸输入字段时才应显示软键盘。我错过了什么吗?
<EditText
android:id="@+id/scanLine"
android:layout_width="253.0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="19.0dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:inputType="text"
android:maxLines="1"
android:focusableInTouchMode="true" />
将以下行添加到 activity 的 onCreate()
方法中:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
希望对您有所帮助!