如何显示在对话框中相应的图标 [英] How to show appropriate icon on dialog box

查看:118
本文介绍了如何显示在对话框中相应的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,允许用户删除视频文件。当我preSS删除按钮,我使用

I have an application that allows the users to delete video files. When I press the delete button, I am using

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        switch (which) {
        case DialogInterface.BUTTON_POSITIVE:
            // mycode........
            break;
        case DialogInterface.BUTTON_NEGATIVE:
            // mycode.....
            break;
        }
    }
};

但这个消息没有警告或删除图标,就像我们在Android设备上看到的。谁能帮我在得到这些图标或使用任何其他警报对话框,可以显示这些图标?

But this message doesn't have a warning or delete icon as we see in android devices. Can anyone help me in getting those icons or using any other alert dialogs that can show those icons?

推荐答案

我倾向于像他们在官方文档的例子显示使用AlertDialog.Builder

I tend to use AlertDialog.Builder like they show in the official doc example

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
   .setCancelable(false)
   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            MyActivity.this.finish();
       }
   })
   .setNegativeButton("No", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
       }
   })
   //Set your icon here
   .setTitle("Alert!")
   .setIcon(R.drawable.icon);
AlertDialog alert = builder.create();
 alert.show();//showing the dialog

至于实际的图标看起来你的SDK文件夹/平台/ Android版#/数据/ RES /绘-MDPI或里面的东西。

As for the actual icon look inside your sdk folder/platforms/android version #/data/res/drawable-mdpi or something

这篇关于如何显示在对话框中相应的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆