2015-10-20 118 views
0

我有我的游戏结果弹出标准AlertDialog,我想把它做大。 这是我创建对话框,并设置代码:如何更改标准警报对话框的大小并使其更大?

@Override 
protected Dialog onCreateDialog(int id) { 
    adb = new AlertDialog.Builder(this); 
    win_lose_view = (RelativeLayout) getLayoutInflater().inflate(R.layout.win_lose_screen, null); 
    adb.setView(win_lose_view); 
    upper_text = (TextView) win_lose_view.findViewById(R.id.upper_text); 
    upper_text.setRotation(180); 
    lower_text = (TextView) win_lose_view.findViewById(R.id.lower_text); 
    upper_decide = (Button) win_lose_view.findViewById(R.id.upper_decide); 
    upper_decide.setRotation(180); 
    lower_decide = (Button) win_lose_view.findViewById(R.id.lower_decide); 
    Dialog d = adb.create(); 
    d.setCanceledOnTouchOutside(false); 
    return d ; 
} 

@Override 
protected void onPrepareDialog(int id, Dialog dialog){ 
    super.onPrepareDialog(id, dialog); 
    upper_decide = (Button) win_lose_view.findViewById(R.id.upper_decide); 
    upper_decide.setRotation(180); 
    lower_decide = (Button) win_lose_view.findViewById(R.id.lower_decide);  
    }; 
    if(first_player_points > second_player_points){ 
     upper_text.setText("you win! score: " + first_player_points); 
     lower_text.setText("you lose! score: "+ second_player_points); 
    } 
} 

这里是它的外观在设备上: ttt

我想让它更广泛的 - 我该怎么做呢?

+0

创建一个具有相同行为的对话框的自定义视图?在中心和黑暗背景下可以查看相对布局? –

+0

你的意思是,没有使用任何标准的警报对话框?只是加载它在游戏结束? – ERJAN

+0

是的。因为你问的对Google来说不是一个好习惯。该对话框具有可观察的最大尺寸。在你的情况下,它是exeptional。所以我认为你应该为此创建一个exerentnel行为。 –

回答

1

你可以创建你的服装布局,并设置onCreateDialog方法。

@Override 
     public Dialog onCreateDialog(Bundle savedInstanceState) { 
     final View view = View.inflate(getActivity(),  R.layout.thalicancle_dialog, null); 

     final Dialog dialog = new Dialog(getActivity(), 0); 

     dialog.setContentView(view); 

}

Custome布局XML。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@mipmap/popupbg" 
android:orientation="vertical" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingTop="@dimen/activity_vertical_margin"> 

1

只需使用的LayoutParams,并更改属性。

AlertDialog dialog = new AlertDialog.Builder(this) 
     .setTitle("Test Dialog") 
     .setMessage("This should expand to the full width") 
     .show(); 
     //Grab the window of the dialog, and change the width 
     WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
     Window window = dialog.getWindow(); 
     lp.copyFrom(window.getAttributes()); 
     //This makes the dialog take up the full width 
     lp.width = WindowManager.LayoutParams.MATCH_PARENT; 
     lp.height = WindowManager.LayoutParams.WRAP_CONTENT; 
     window.setAttributes(lp); 
1

在显示对话框后使用getWindow()。setLayout(width,height)。

alertDialogBuilder 
     .setMessage("Click yes to exit!") 
     .setCancelable(false) 
     .setPositiveButton("Yes",new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog,int id) { 
       // if this button is clicked, close 
       // current activity 
       MainActivity.this.finish(); 
      } 
      }) 
     .setNegativeButton("No",new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog,int id) { 
       // if this button is clicked, just close 
       // the dialog box and do nothing 
       dialog.cancel(); 
      } 
     }).show().getWindow().setLayout(600,500); 
相关问题