首页 > 解决方案 > DialogFragment中edittext的光标气泡位置

问题描述

我有一个带有 EditText 的示例对话框片段。它始终在设备屏幕顶部显示光标气泡。但对话框出现在中心。我尝试更改活动主题并尝试自定义对话框,但没有解决问题。谁能帮我解决这个问题。

在此处输入图像描述 这是我用来显示对话框的代码

public class SampleAlertDialog extends DialogFragment {

    public static SampleAlertDialog getInstance() {
        SampleAlertDialog dialog = new SampleAlertDialog();
        return dialog;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        builder.setView(inflater.inflate(R.layout.layout_dialog, null))
                // Add action buttons
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // sign in the user ...
                    }
                })
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
        return builder.create();
    }

}

对话框的 XML 文件是

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/edt_dialog"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

</android.support.constraint.ConstraintLayout>

标签: androiddialogandroid-themedialogfragment

解决方案


推荐阅读