【问题标题】:Android dialog with icon in subtitle带有字幕图标的 Android 对话框
【发布时间】:2022-01-18 07:38:59
【问题描述】:

我正在尝试使用 android 对话框,图标设置为字幕。我正在使用下面的代码,但在标题中获得了图标。我正在尝试获取类似于附加图像的内容。

dialogBox = new MaterialAlertDialogBuilder(dialogContext)
                        .setTitle("Power Off")// getting image in title
                        .setMessage("Shutting Down")// Need image here
                        .setIcon(R.mipmap.loader)
                        .setCancelable(false)
                        .show();

【问题讨论】:

  • 您应该为此使用自定义对话框。

标签: android dialog


【解决方案1】:

这里是解决方案

final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setTitle(R.string.my_dialog_title);
dialog.setContentView(R.layout.my_dialog_layout);
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.mipmap.loader);
dialog.show(); 

如果您希望您的对话框看起来像活动,然后将主题添加到对话框中,如下所示

final Dialog dialog = new Dialog(this,AlertDialog.THEME_HOLO_LIGHT);  

show().之后调用setFeatureDrawableResource()

不知道为什么会这样。 :)

【讨论】:

    【解决方案2】:

    请尝试以下代码。

    
    dialogBox = new MaterialAlertDialogBuilder(dialogContext)
                            .setTitle("Power Off")// getting image in title
                            .setMessage("Shutting Down")// Need image here
                            .setIcon(dialogContext.getResources().getDrawable(R.mipmap.loader))
                            .setCancelable(false)
                            .show();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-03
      • 2020-03-14
      • 2012-03-11
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多