【问题标题】:EditText disappearing from dialog in AndroidEditText从Android中的对话框中消失
【发布时间】:2021-04-14 09:07:55
【问题描述】:

我的对话框中需要几个编辑文本,我通常在 xml 中添加它们,但打开时它们会消失这是我的代码:

public class SubmissionDialog extends AppCompatDialogFragment {
    private TextProcessor tpCode;
    private EditText etOutput;
    private EditText etExpectedOutput;

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.view_submission_dialog, null);
        Bundle bundle = this.getArguments();

        builder.setView(view)
                .setTitle("Task submission.")
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // nothing
                    }
                });

        tpCode = (TextProcessor) view.findViewById(R.id.tpCodeDialog);
        etOutput = (EditText) view.findViewById(R.id.etDialogOutput);
        etExpectedOutput = (EditText) view.findViewById(R.id.etDialogExpectedOutput);

        tpCode.setTextContent(bundle.getString("code"));
        tpCode.setLanguage(new JavaLanguage());
        tpCode.setColorScheme(EditorTheme.INSTANCE.getMONOKAI());

        etOutput.setText(bundle.getString("output"));
        etExpectedOutput.setText(bundle.getString("expectedOutput"));

        return builder.create();
    }
}

这特别奇怪,因为我做了很多次,但只是这次它消失了,我检查 bundle 不是空的,在我的 xml 中也没有错误。

【问题讨论】:

  • 你是否使用了匹配约束的高度元素的约束布局
  • @devfoFikiCar 是在编辑文本部分

标签: android android-studio user-interface android-edittext


【解决方案1】:

由于您在 cmets 中告诉我您使用了约束布局并且在上面的注释中具有 0dp 的高度元素,因此您需要删除它们,因为警报对话框不像通常的布局那样具有高度限制,所以您的编辑文本在那里但是因为它们匹配不存在的约束,它们是不可见的。您应该或使用不同的布局类型或包装内容,您真的不应该关心警报对话框中的高度。

【讨论】:

  • 我改为包装内容并且它有效。谢谢
猜你喜欢
  • 2012-02-10
  • 1970-01-01
  • 2019-09-05
  • 2011-09-30
  • 2011-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多