Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 警报对话框图标赢得';t集_Java_Android - Fatal编程技术网

Java 警报对话框图标赢得';t集

Java 警报对话框图标赢得';t集,java,android,Java,Android,我的可绘制hdpi文件夹中有一个14x14 png文件(icon_alert.png)。这是我设置图标的方式: alertDialog.setIcon(R.drawable.icon_alert); 显示对话框时图标不在那里。您可以使用alertDialog.setIcon(R.drawable.icon) public class ExampleApp extends Activity { @Override protected void onCreate(Bundle savedInsta

我的可绘制hdpi文件夹中有一个14x14 png文件(icon_alert.png)。这是我设置图标的方式:

alertDialog.setIcon(R.drawable.icon_alert);

显示对话框时图标不在那里。

您可以使用
alertDialog.setIcon(R.drawable.icon)

public class ExampleApp extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
alt_bld.setMessage("Do you want to close this window ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//  Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Title");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();
}
}

图标必须是
.png
.jpg
,我强烈推荐16X16。

您可以使用
alertDialog.setIcon(R.drawable.icon)


图标必须是
.png
.jpg
,我强烈建议使用16X16。

您也需要一个标题,否则它将无法工作。

您也需要一个标题,否则它将无法工作