AlertDialog按钮大小不变

时间:2013-01-20 07:41:50

标签: android android-layout android-alertdialog android-button android-dialog

我有一个具有Background资源的警报Dialog。当我设置背景资源时,图像的大小占据了我屏幕中的大空间。请让我知道如何控制按钮的大小。提前谢谢。

以下是代码段。

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;  

1 个答案:

答案 0 :(得分:0)

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