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

      <legend id='LsRtZ'><style id='LsRtZ'><dir id='LsRtZ'><q id='LsRtZ'></q></dir></style></legend>
      1. <small id='LsRtZ'></small><noframes id='LsRtZ'>

        <tfoot id='LsRtZ'></tfoot>
      2. 主题不适用于 Android 上的 DialogFragment

        时间:2023-08-29
      3. <small id='kyVJr'></small><noframes id='kyVJr'>

                <bdo id='kyVJr'></bdo><ul id='kyVJr'></ul>
                  <tbody id='kyVJr'></tbody>
              • <legend id='kyVJr'><style id='kyVJr'><dir id='kyVJr'><q id='kyVJr'></q></dir></style></legend>
                1. <tfoot id='kyVJr'></tfoot>
                  <i id='kyVJr'><tr id='kyVJr'><dt id='kyVJr'><q id='kyVJr'><span id='kyVJr'><b id='kyVJr'><form id='kyVJr'><ins id='kyVJr'></ins><ul id='kyVJr'></ul><sub id='kyVJr'></sub></form><legend id='kyVJr'></legend><bdo id='kyVJr'><pre id='kyVJr'><center id='kyVJr'></center></pre></bdo></b><th id='kyVJr'></th></span></q></dt></tr></i><div id='kyVJr'><tfoot id='kyVJr'></tfoot><dl id='kyVJr'><fieldset id='kyVJr'></fieldset></dl></div>

                2. 本文介绍了主题不适用于 Android 上的 DialogFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在将旧 Dialogs 切换为 DialogFragment,但主题和样式似乎不起作用.

                  I'm switching my old Dialogs to DialogFragment, but the themes and styles don't seem to be working.

                  我正在使用兼容库 v4 中的 DialogFragment,并且在 onCreate 方法中我尝试调用 setStyle(style, theme);有很多不同的主题,但对话框总是在运行 Android 4.0.3 的模拟器中显示为旧"对话框(即,它不显示在 Holo 主题中).

                  I'm using the DialogFragment from the compatibility library v4, and in the onCreate method I've tried calling setStyle(style, theme); with a lot of different themes, but the dialog always shows as an "old" dialog in the emulator running Android 4.0.3 (i.e., it does not shows in Holo theme).

                  还有什么我应该做的吗?使用兼容性库是否会禁用 Holo 主题或任何东西?如果是这种情况,我是否应该创建两个 DialogFragment,一个用于旧版本,一个用于新版本?

                  Is there anything else that I should be doing? Does using the compatibility library disables the Holo theme or anything? If this is the case, should I create two DialogFragments, one for older versions and one for newer versions?

                  谢谢!

                  这是我的对话框的(简化的)代码.我已经尝试过 Theme_Holo_Dialog_NoActionBar 和 Theme_DeviceDefault_Dialog_NoActionBar,但 Android 4 模拟器总是将对话框显示为旧"对话框,而不是使用 Holo 主题.我究竟做错了什么?:(

                  Here's the (simplified) code for my dialog. I've tried both Theme_Holo_Dialog_NoActionBar and Theme_DeviceDefault_Dialog_NoActionBar, but the Android 4 emulator always shows the dialog as an "old" dialog instead of using the Holo theme. What am I doing wrong? :(

                  [...]
                  import android.support.v4.app.DialogFragment;
                  [...]
                  
                  public class AlertDialogFragment extends DialogFragment {
                  
                    public static AlertDialogFragment newInstance(int id) {
                  
                      AlertDialogFragment f = new AlertDialogFragment();
                      Bundle args = new Bundle();
                      args.putInt("id", id);
                      f.setArguments(args);
                  
                   }
                  
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                      super.onCreate(savedInstanceState);
                      int style = DialogFragment.STYLE_NORMAL, theme = 0;
                      theme = android.R.style.Theme_Holo_Dialog_NoActionBar;
                      setStyle(style, theme);     
                    }
                  
                    @Override
                    public Dialog onCreateDialog(Bundle savedInstanceState) {
                  
                      mId = getArguments().getInt("id");
                      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
                          .setTitle(mTitle)
                          .setMessage(mMessage)
                          .setPositiveButton(getString(R.string.btn_ok), new DialogInterface.OnClickListener() {      
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                  dismiss();                  
                              }
                          });
                          return builder.create();
                      }
                  

                  推荐答案

                  我相信你需要在实际的Dialog而不是Fragment上设置主题

                  I believe you need to set the theme on the actual Dialog and not the Fragment

                  使用此构造函数创建您的 AlertDialog:

                  Use this constructor to create your AlertDialog:

                   AlertDialog.Builder(Context context, int theme)
                  

                   AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), theme)
                  

                  这篇关于主题不适用于 Android 上的 DialogFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何创建将在水平维度上充满的对话框 下一篇:Dialog.show() 与 Activity.showDialog()

                  相关文章

                  最新文章

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

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

                    <small id='l8M1s'></small><noframes id='l8M1s'>

                      • <bdo id='l8M1s'></bdo><ul id='l8M1s'></ul>