Newbie
Newbie

Reputation: 129

How to change the font size of dialog title and list items?

I would like to change the font size of the dialog in android. I don't want to create a custom dialog for it.

the following is my code

final String[] items = {"portfolioId", "portfolioType", "portfolioRefCcy"}; 
    final boolean [] selected = {false, false, false};  

AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Select atmost 3 output paramters to display..")
    .setCancelable(false)
    .setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {     
        public void onClick(DialogInterface dialogInterface, int item, boolean b) 
        {         
            selected[item] = b;     
            int total_selected = 0;  
            for(int i=0; i<items.length; i++)
            {
                if(Boolean.toString(selected[i]).equals("true"))
                {
                    total_selected++;
                }
            }
            if(total_selected > 3)
            {   
                selected[item] = false;
                ((AlertDialog) dialogInterface).getListView().setItemChecked(item, false);
                Toast.makeText(getApplicationContext(), "Cannot select anymore categories!", Toast.LENGTH_SHORT).show();
            }
            else
            {
                ((AlertDialog)dialogInterface).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }
        } 

        })
    .setPositiveButton("Ok", new DialogInterface.OnClickListener() {                
        @Override                
        public void onClick(DialogInterface dialog, int id) 
        {              
        }) 
    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {               
        @Override                
        public void onClick(DialogInterface dialog, int id) 
        {                          

        }}); 
    AlertDialog dialog = builder.create();
    dialog.show();

Is there any way around that I can use the same code and change the title font size and the multi choice list items font size without creating a custom dialog.

Upvotes: 0

Views: 6584

Answers (1)

A.Ruppin
A.Ruppin

Reputation: 161

You can do customizing of dialog title by using setCustomDialog() API.

Sample for the same is as follows,

AlertDialog.Builder builder = new AlertDialog.Builder(this);    
final TextView myView = new TextView(getApplicationContext());
myView.setText("A Sample Title to Change Dialog Title");
myView.setTextSize(12);     
builder.setCustomTitle(myView); // set custom view

Upvotes: 3

Related Questions