1

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

以下是代码片段。

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;  
4

1 回答 1

0

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

于 2013-04-25T09:37:07.457 回答