0

i want have my custom header for my CustomAlert. what do i do for my custom layout for Dialog,s title?

Edit2: i added my code:

    protected Dialog onCreateDialog(int id) 
        {           
            switch(id)
            {           
            case Dialog_Reset :     
            Dialog dialog=new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.about);  
            dialog.setCanceledOnTouchOutside(true);         
            return dialog;
            }
            return super.onCreateDialog(id);
       } 

and becuse i dont like default header in dialog,i remove it now,while i learn having my custom header.

setare shojaei
  • 145
  • 1
  • 12

2 Answers2

1

but i dont understand what is "titleId". is it what really? is it my special layout designed that i want use for title?

titleId : title identifier in other words a string resource identifier, e.g. R.string.app_name. You can add these in strings.xml found at res > values folders

Android Dev Doc: Dialog.setTitle (int titleId)

More about string resources here

Community
  • 1
  • 1
madlymad
  • 6,367
  • 6
  • 37
  • 68
0

You can set CustomTitle of your Alert Dialog using public AlertDialog.Builder setCustomTitle (View customTitleView) method.

As per documentation

public AlertDialog.Builder setCustomTitle (View customTitleView)

Set the title using the custom view customTitleView. The methods setTitle(int) and setIcon(int) should be sufficient for most titles, but this is provided if the title needs more customization. Using this will replace the title and icon set via the other methods.

Parameters customTitleView The custom view to use as the title. Returns This Builder object to allow for chaining of calls to set methods

example

LayoutInflater inflater = (LayoutInflater)yourClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View yourView= inflater.inflate(R.layout.custom_dialog, null);

AlertDialog.Builder ab= new AlertDialog.Builder(this);
ab.setCustomTitle(yourView);
ab.setMessage(message);
...


 ab.create();
 ab.show();

for details see the documentation

Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30