键盘未显示在警报对话框中的焦点上

Keyboard doesn't show on focus in alert dialog

我有一个从自定义 PopupDialog 扩展而来的对话框。

问题是键盘不会出现在焦点 EditText 字段上。我试过 clearFlags 和其他东西,但问题仍然存在。

public class PopupDialog<RESULT> extends AlertDialog {
private final View mContentView;
private final AppActivity mActivity;

/**
 * Sets the activity and Content View.
 *
 * @param activity
 *            The activity which is used.
 * @param content
 *            The main content of dialog window.
 */
public PopupDialog(final AppActivity activity, final int content) {
    super(activity);
    mActivity = activity;

    // Set the content
    mContentView = getLayoutInflater().inflate(R.layout.z__dialog, null, false);
    setView(mContentView);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    setView(mContentView, 0, 0, 0, 0);

    // Set the background to white
    setInverseBackgroundForced(true);

    getWindow().setBackgroundDrawableResource(R.color.transparent);
    show();

    // Inflate the content
    View.inflate(activity, content, (ViewGroup) findViewById(R.id.dialog_content)).setLayoutParams(new LinearLayout.LayoutParams(700, LayoutParams.WRAP_CONTENT));
}

我猜想您的 EditText 不可聚焦或在触摸模式下不可聚焦,但如果没有看到该视图的 xml 则无法确定。可以post吗?

我在 xml 中添加了一个 EditText,并在代码 this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

中禁用了焦点

现在可以使用了。不干净,但它正在工作。

<LinearLayout
    android:id="@+id/dialog_frame"
    style="@style/vertical"
    android:gravity="center" >

    <requestFocus />

    <FrameLayout
        android:id="@+id/dialog_content"
        style="@style/block" />

    <EditText
        android:id="@+id/editext"
        style="@style/block"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:visibility="gone" />

    <LinearLayout
        android:id="@+id/dialog_buttons"
        style="@style/horizontal"
        android:layout_width="wrap_content"
        android:paddingBottom="@dimen/padding_middle" />
</LinearLayout>