【问题标题】:How to change the color of Dialog box如何更改对话框的颜色
【发布时间】:2010-12-08 10:24:25
【问题描述】:

当我在不同的设备中安装我的应用程序时,对话框的颜色将设备更改为设备 如何设置对话框的颜色

问候, 刽子手

【问题讨论】:

    标签: android user-interface dialog


    【解决方案1】:

    你对anddev.org 有一些线索。基本思想是扩展默认主题并在您的活动中使用它。特别是,您需要扩展 Theme.Dialog 样式。

    【讨论】:

      【解决方案2】:

      您能否命名您用来测试的设备?...它们可能包含定制的 Android 版本,因此对话框颜色会发生变化。您可以保持原样,因为您的构建将使用设备可用的默认样式,否则请尝试设置样式以避免这种行为。

      【讨论】:

        【解决方案3】:

        通过设置对话框主题将活动用作对话框。然后,您可以使用自己的背景和颜色来扩充自己的布局。

        【讨论】:

          【解决方案4】:

          更改 DialogBox 的颜色并使用 AlertDialog 做更多事情。

          你必须做什么:

          AlertDialog 在您的屏幕上可见时,会调用OnShowListener。因此,通过添加dialog.setOnShowListener(this),您将能够自定义您的AlertDialog

          代码:

          // Create AlertDialog
          AlertDialog.Builder adb = new AlertDialog.Builder(context1);
              adb.setTitle(context1.getString(R.string.app_name))
              .setMessage(message)
              .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
          
                  }
          });
          AlertDialog dialog = adb.create();
          
          // Make some UI changes for AlertDialog
          dialog.setOnShowListener(new DialogInterface.OnShowListener() {
              @Override
              public void onShow(final DialogInterface dialog) {
          
                  // Add or create your own background drawable for AlertDialog window
                  Window view = ((AlertDialog)dialog).getWindow();
                  view.setBackgroundDrawableResource(R.drawable.your_drawable);
          
                  // Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
                  Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
                  positiveButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
                  positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
                  positiveButton.invalidate();
          
                  Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
                  negativeButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
                  negativeButton.setTypeface(Typeface.DEFAULT_BOLD);
                  negativeButton.invalidate();
          
                  Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL);
                  neutralButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
                  neutralButton.setTypeface(Typeface.DEFAULT_BOLD);
                  neutralButton.invalidate();
              }
          });
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-04-28
            • 1970-01-01
            • 1970-01-01
            • 2019-11-24
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多