• <small id='6jwOX'></small><noframes id='6jwOX'>

  • <legend id='6jwOX'><style id='6jwOX'><dir id='6jwOX'><q id='6jwOX'></q></dir></style></legend>
      <bdo id='6jwOX'></bdo><ul id='6jwOX'></ul>

    <tfoot id='6jwOX'></tfoot>

      <i id='6jwOX'><tr id='6jwOX'><dt id='6jwOX'><q id='6jwOX'><span id='6jwOX'><b id='6jwOX'><form id='6jwOX'><ins id='6jwOX'></ins><ul id='6jwOX'></ul><sub id='6jwOX'></sub></form><legend id='6jwOX'></legend><bdo id='6jwOX'><pre id='6jwOX'><center id='6jwOX'></center></pre></bdo></b><th id='6jwOX'></th></span></q></dt></tr></i><div id='6jwOX'><tfoot id='6jwOX'></tfoot><dl id='6jwOX'><fieldset id='6jwOX'></fieldset></dl></div>

        最简单的是/否对话框片段

        时间:2023-08-29
          <tfoot id='AdPuK'></tfoot>
          <i id='AdPuK'><tr id='AdPuK'><dt id='AdPuK'><q id='AdPuK'><span id='AdPuK'><b id='AdPuK'><form id='AdPuK'><ins id='AdPuK'></ins><ul id='AdPuK'></ul><sub id='AdPuK'></sub></form><legend id='AdPuK'></legend><bdo id='AdPuK'><pre id='AdPuK'><center id='AdPuK'></center></pre></bdo></b><th id='AdPuK'></th></span></q></dt></tr></i><div id='AdPuK'><tfoot id='AdPuK'></tfoot><dl id='AdPuK'><fieldset id='AdPuK'></fieldset></dl></div>

              <legend id='AdPuK'><style id='AdPuK'><dir id='AdPuK'><q id='AdPuK'></q></dir></style></legend>

              1. <small id='AdPuK'></small><noframes id='AdPuK'>

                  <tbody id='AdPuK'></tbody>

                  <bdo id='AdPuK'></bdo><ul id='AdPuK'></ul>
                  本文介绍了最简单的是/否对话框片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想制作一个对话片段,询问你确定吗?"回复是/否".

                  I'd like to make a dialog fragment that asks "Are you sure?" with a "yes/no" reply.

                  我查看了文档,它真的很冗长,到处都是这个地方,解释了如何制作高级对话框,但没有完整的代码来制作一个简单的hello world"类型的对话框.大多数教程使用已弃用的对话框系统.官方博客似乎过于复杂且难以理解.

                  I've looked at the documentation and it's really verbose, going all over the place, explaining how to make advanced dialog boxes, but no intact code on making a simple 'hello world' kind of dialog box. Most tutorials utilize the deprecated dialog box system. The official blog seems to be unnecessarily complicated and difficult to understand.

                  那么,创建和显示一个真正基本的警报对话框的最简单方法是什么?使用支持库的奖励积分.

                  So, what's the simplest way to create and display a really basic Alert Dialog? Bonus points if it's using the support library.

                  推荐答案

                  DialogFragment 其实就是一个包装了对话框的片段.您可以通过在 DialogFragment 的 onCreateDialog() 方法中创建并返回对话框来将任何类型的对话框放入其中.

                  A DialogFragment is really just a fragment that wraps a dialog. You can put any kind of dialog in there by creating and returning the dialog in the onCreateDialog() method of the DialogFragment.

                  这是一个示例 DialogFragment:

                  Heres an example DialogFragment:

                  class MyDialogFragment extends DialogFragment{
                      Context mContext;
                      public MyDialogFragment() {
                          mContext = getActivity();
                      }
                      @Override
                      public Dialog onCreateDialog(Bundle savedInstanceState) {
                          AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
                          alertDialogBuilder.setTitle("Really?");
                          alertDialogBuilder.setMessage("Are you sure?");
                          //null should be your on click listener
                          alertDialogBuilder.setPositiveButton("OK", null);
                          alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                  
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                  dialog.dismiss();
                              }
                          });
                  
                  
                          return alertDialogBuilder.create();
                      }
                  }
                  

                  创建对话调用:

                  new MyDialogFragment().show(getFragmentManager(), "MyDialog");
                  

                  并从某处关闭对话框:

                  ((MyDialogFragment)getFragmentManager().findFragmentByTag("MyDialog")).getDialog().dismiss();
                  

                  只需更改导入以使用支持库类,所有这些代码都将与支持库完美配合.

                  All of that code will work perfectly with the support library, by just changing the imports to use the support library classes.

                  这篇关于最简单的是/否对话框片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:不推荐使用 showDialog.有什么选择? 下一篇:使用 Dialog 自定义屏幕变暗

                  相关文章

                  最新文章

                    <bdo id='7sgb2'></bdo><ul id='7sgb2'></ul>
                  <i id='7sgb2'><tr id='7sgb2'><dt id='7sgb2'><q id='7sgb2'><span id='7sgb2'><b id='7sgb2'><form id='7sgb2'><ins id='7sgb2'></ins><ul id='7sgb2'></ul><sub id='7sgb2'></sub></form><legend id='7sgb2'></legend><bdo id='7sgb2'><pre id='7sgb2'><center id='7sgb2'></center></pre></bdo></b><th id='7sgb2'></th></span></q></dt></tr></i><div id='7sgb2'><tfoot id='7sgb2'></tfoot><dl id='7sgb2'><fieldset id='7sgb2'></fieldset></dl></div>

                      <small id='7sgb2'></small><noframes id='7sgb2'>

                      <legend id='7sgb2'><style id='7sgb2'><dir id='7sgb2'><q id='7sgb2'></q></dir></style></legend>
                      <tfoot id='7sgb2'></tfoot>