1

我有一个警报对话框,它有一个背景资源。当我设置一个背景资源时,图像的大小占据了我屏幕上的一个主要空间。请让我知道如何控制按钮的大小。提前致谢。AlertDialog按钮大小不变

以下是代码片段。

public void onClick(View v) { 
    // TODO Auto-generated method stub 
    switch (v.getId()){ 
    case R.id.bNewTicket:  
     // custom dialog 
     LayoutInflater li = LayoutInflater.from(context); 
     final View promptsView = li.inflate(R.layout.homepagedialognewticket, null); 
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); 
     alertDialogBuilder.setView(promptsView); 


     // set dialog message 
     alertDialogBuilder.setPositiveButton("Go", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
        EditText etTableNumber,etGuestCount; 
        etTableNumber = (EditText) promptsView.findViewById(R.id.etTableNumber); 
        etGuestCount = (EditText) promptsView.findViewById(R.id.etGuestCount); 
        tableNumber = etTableNumber.getText().toString(); 
        guestCount = etGuestCount.getText().toString(); 
        dialog.cancel(); 
        if (tableNumber.isEmpty() || guestCount.isEmpty()) { 
         Dialog d = new Dialog(context); 
         d.setTitle("Alert "); 
         TextView tv = new TextView(context); 
         tv.setText("Table # and Guest # are mandatory "); 
         d.setContentView(tv); 
         d.show(); 
        } else{ 
         new longRunningProcess().execute("newticket",null,null); 
         } 
       } 
       }) 
       .setNegativeButton("Back",new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog,int id) { 
       dialog.cancel(); 
       } 
       }); 

     AlertDialog alertDialog = alertDialogBuilder.create(); 
     alertDialog.show(); 

     Button imagebutt = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); 
     imagebutt.setBackgroundResource(R.drawable.go); 

     if (imagebutt != null) imagebutt.setHeight(20); 
     break; 

回答

0

尝试在alertDialog上的show()后对按钮执行setHeight。