android dialog set icon to title
android, android-dialog
Solution
follow this on any `button` click or on your `onActivity` or any place you want this dialog to show. do read my comments every after `//`
AlertDialog alertDialog = new AlertDialog.Builder(
this).create();
alertDialog.setTitle("TITLE"); // your dialog title
alertDialog.setMessage("Your message"); // a message above the buttons
alertDialog.setIcon(R.drawable.ic_home); // the icon besides the title you have to change it to the icon/image you have.
alertDialog.setButton("Got IT", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { // here you can add a method to the button clicked. you can create another button just by copying alertDialog.setButton("okay")
}
});
alertDialog.show();
do me a favor and delete this
public DialogMealInformation(Context context, String information) {
// TODO Auto-generated constructor stub
super(context);
this.context = context;
this.information = information;
setContentView(R.layout.dialog_meal_information);
getWindow().setLayout(android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
setTitle("Info !");
initialize();
}
and add mine instead !
Problem
I have this dialog class and i want to set icon to its title: ``` public class DialogMealInformation extends Dialog implements android.view.View.OnClickListener { Context context; private TextView tv_information; private Button b_ok; private String information; public DialogMealInformation(Context context, String information) { // TODO Auto-generated constructor stub super(context); this.context = context; this.information = information; setContentView(R.layout.dialog_meal_information); getWindow().setLayout(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); setTitle("Info !"); initialize(); } ``` it tried like this: ``` setTitle(R.layout.dialog_simple_header); ``` dialog_simple_header.xml ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:id="@+id/tv_dialog_simple_header_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_information" android:drawableLeft="@drawable/more_information" /> </LinearLayout> ``` but the title after that was "res/layout/dialog_simple_header.x" just text, no icon is appear, why please , what is the solution , thanks alot