[英]How to open a AlertDialog in a full width of screen
我想要下面的對話框。 。 因此,我以AlertDialog以及使用自定義警報對話框的形式打開了活動。 自定義AlertDialog的代碼如下
LayoutInflater inflater = LayoutInflater.from(this);
View dialogLayout = inflater.inflate(R.layout.add_user_dialoge, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogLayout);
AlertDialog customAlertDialog = builder.create();
WindowManager.LayoutParams wmlp = customAlertDialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.START;
wmlp.y = 120;//y position
customAlertDialog.show();
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int displayWidth = displayMetrics.widthPixels;
int dialogWindowWidth = (int) (displayWidth *2);
wmlp.width = dialogWindowWidth;
customAlertDialog.getWindow().setAttributes(wmlp);
可以通過兩種方式完成此操作,第一種是在style.xml中,第二種是在代碼中:
<style name="Theme_Dialog" parent="android:Theme.Holo.Dialog"> <item name="android:windowMinWidthMajor">90%</item> <item name="android:windowMinWidthMinor">90%</item> </style>
final Dialog contacts_dialog = new Dialog(ActivityGroup.this, R.style.theme_sms_receive_dialog); contacts_dialog.setContentView(R.layout.dialog_schedule_date_time);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
contacts_dialog.setCancelable(true);
contacts_dialog.setCanceledOnTouchOutside(true);
contacts_dialog.show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.