簡體   English   中英

如何在整個屏幕上打開AlertDialog

[英]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中,第二種是在代碼中:

  1. 在style.xml中添加以下內容,更改值(當前為90%)以滿足您的需求。
 <style name="Theme_Dialog" parent="android:Theme.Holo.Dialog"> <item name="android:windowMinWidthMajor">90%</item> <item name="android:windowMinWidthMinor">90%</item> </style> 
  1. 將布局添加到match_parent
  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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM