【问题标题】:How to make a custom dialog in Android [duplicate]如何在Android中制作自定义对话框[重复]
【发布时间】:2017-10-19 10:01:20
【问题描述】:

我想制作一个自定义警报对话框,例如这张图片 我会怎么做? 我想设计这个对话框Alert Dialog

【问题讨论】:

  • 到目前为止你做了什么?你的代码在哪里?
  • 我想设计这个对话框,我不知道如何设计它

标签: android android-layout android-studio android-alertdialog android-dialogfragment


【解决方案1】:

如果你还想要自定义标题,首先你需要为你的标题创建一个新的布局 xml 文件和一个新的布局。

 final AlertDialog dialog;

    final View alertDialogView = LayoutInflater.from(getContext()).inflate
            (R.layout.your_layout, null);
    final View titleView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_layout, null);

 dialog = new AlertDialog.Builder(getContext())
            .setView(alertDialogView)
            .setCustomTitle(titleView)
            .setPositiveButton(R.string.set, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  ///do your job
            })
            .setCancelable(true)
            .create();


    dialog.show();

如果你想从自定义布局访问标题,你可以通过这种方式访问​​它:

((TextView) titleView.findViewById(R.id.title)).setText(getString(R.string.
your_string));

【讨论】:

  • 我在执行中没有任何问题
猜你喜欢
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多