Android - AlertDialog 的奇怪行为
Android - Weird behaviour with AlertDialog
我有一个包含 ListView 的 AlertDialog。 ListView 上的一项具有 EditText。
当点击 EditText 时,键盘不会显示 :
EditText
的代码(我认为这不是导致问题的原因)
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editableEditText"
android:layout_weight="1"
android:maxLines="1"/>
尝试使用setSoftInputMode
示例代码片段 -
AlertDialog.Builder b = new AlertDialog.Builder(this);
...
AlertDialog dialog = b.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
尝试添加此代码:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
应该是这样的。对我有用
编辑:
这是我发现的另一种方式:
Dialog = builder.create(); Dialog.show();
Dialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
试一试
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
我有一个包含 ListView 的 AlertDialog。 ListView 上的一项具有 EditText。
当点击 EditText 时,键盘不会显示 :
EditText
的代码(我认为这不是导致问题的原因)
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editableEditText"
android:layout_weight="1"
android:maxLines="1"/>
尝试使用setSoftInputMode
示例代码片段 -
AlertDialog.Builder b = new AlertDialog.Builder(this);
...
AlertDialog dialog = b.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
尝试添加此代码:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
应该是这样的。对我有用
编辑:
这是我发现的另一种方式:
Dialog = builder.create(); Dialog.show();
Dialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
试一试
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);