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

sAaNu picture sAaNu · Feb 24, 2012 · Viewed 31.9k times · Source

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

Answer

Vikram picture Vikram · Feb 24, 2012

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