Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to include custom title view with in AlertDialog in android?

how can i include custom titlebar in alertDialog?I know android sdk provide setCustomTitle method but it does'not work

edit:

    AlertDialog alert = new AlertDialog.Builder(this).setTitle("Test").setMessage("hello").show();
    View view=alert.getLayoutInflater().inflate(R.layout.titlebar, null);
    alert.setCustomTitle(view);

but above code is not working

NOTE : I am not looking for custom dialog box but only want to makes its title layout custom..Like belowlike this with close Button

like image 800
sAaNu Avatar asked Feb 24 '12 11:02

sAaNu


People also ask

Which method is used to set a title to a Alert Dialog?

In the following code setTitle() method is used for set Title to alert dialog. setMessage() is used for setting message to alert dialog. setIcon() is to set icon to alert dialog.

Is AlertDialog deprecated?

This method is deprecated.

How do I change the font in AlertDialog?

Get AlertDialog title by findViewById. Material Dialog Change Text Sizes. Change fontsize for ListView in an AlertDialog.


1 Answers

you should not use the .show method with the first line, use the following code it works:

AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.titlebar, null);
alert.setCustomTitle(view);
alert.setMessage("helo");
alert.show();
like image 164
Vikram Avatar answered Oct 20 '22 20:10

Vikram