1. android 怎麼讓自定義dialog的寬度充滿整個屏幕
AlertDialog dialog = builder.create();
dialog.setView(view);
dialog.show();
WindowManager m = getWindowManager();
Display d = m.getDefaultDisplay(); //為獲取屏幕寬、高
android.view.WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //獲取對話框當前的參數值
p.height = (int) (d.getHeight() * 0.3); //高度設置為屏幕的0.3
p.width = (int) (d.getWidth() * 0.5); //寬度設置為屏幕的0.5
dialog.getWindow().setAttributes(p); //設置生效
這個可以給你參考一下,你應該是自定義樣式的dialog 你只需要在dialog.setView(view);之前把你的布局載入進去就可以了。
2. android dialog怎麼設置大小
1)更改AlertDialog窗口大小的方法:
AlertDialog dialog = new AlertDialog.Builder
(this).create();
dialog.show();
WindowManager.LayoutParams params =
dialog.getWindow().getAttributes();
params.width = 200;
params.height = 200 ;
dialog.getWindow().setAttributes(params);
注意:是先顯示出來dialog,show()出來,才能再設置寬高屬性
2
2)去除邊框
AlertDialog.setView(view,0,0,0,0);