【问题标题】:AlertDialog Button size is not changingAlertDialog 按钮大小没有改变
【发布时间】:2013-01-03 13:29:25
【问题描述】:

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

下面是代码sn-p。

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;  

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-27
      • 2011-12-17
      • 2015-09-09
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多