2011-09-11 33 views
1

私のdrawable-hdpiフォルダに14x14 pngファイル(icon_alert.png)があります。これは、アイコンを設定する方法です。警告ダイアログアイコンが設定されない

alertDialog.setIcon(R.drawable.icon_alert); 

ダイアログが表示されてもアイコンは表示されません。あなたはアイコンが.pngまたは.jpgのいずれかでなければなりませんalertDialog.setIcon(R.drawable.icon);

を使用することができます

答えて

1
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(); 
} 
} 
1

、私は非常に16X16をお勧めします。

2

タイトルも必要です。そうでないとうまくいかないでしょう。

関連する問題