android - 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>
解决方案
推荐阅读
- python - Python - win32com.client:尝试打开(大)Excel 时出现 pywintypes.com_error
- sql - 计算一定时间间隔内的平均值
- javascript - 存储点击值以供以后使用
- arrays - 检查数组中的子字符串并在 ruby 中替换它们
- python - 当 C++ 和 Python 文件不在同一个文件夹中时,如何在 Pybind11 中导入 Python 脚本?
- python - 子进程的输出在时间之前被附加到文件中
- error-handling - 如何返回包含来自结果迭代器的每个错误的结果,而不仅仅是第一个?
- fullcalendar - jQuery Fullcalendar - 每个事件将可编辑事件更改为不可编辑(反之亦然)
- windows - 如何将窗口添加到登录服务器
- php - 如果以编程方式发送,Magento 2 将以英文发送电子邮件