0

我想在android中更改对话框的字体大小。我不想为它创建一个自定义对话框。

以下是我的代码

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

有什么办法可以让我使用相同的代码并更改标题字体大小和多选列表项字体大小,而无需创建自定义对话框。

4

1 回答 1

3

您可以使用 setCustomDialog() API 自定义对话框标题。

相同的示例如下,

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
于 2013-07-10T09:45:20.510 回答