如何在整个屏幕上打开AlertDialog

时间:2018-07-02 07:19:41

标签: android android-layout android-alertdialog

我想要如下所示的对话框。 this。因此,我以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);

但其给出的答案如下。this。如何删除已标记的左侧空间?

1 个答案:

答案 0 :(得分:1)

可以通过两种方式完成操作,第一种在style.xml中,第二种在代码中:

  1. 在style.xml中添加以下内容,更改值(当前为90%)以满足您的需求。
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="utf-8">
<?php
    ...
    $name = $_POST['cust_name'];
    $name = iconv('UTF-8', 'UTF-16LE', $name);
    $name = bin2hex($name);
    $sql  = "INSERT INTO inv01 (cust) VALUES (CONVERT(nvarchar(MAX), 0x".$value."))";
    ...
?>
</head>
<body></body>
</html>
  1. 将布局添加到match_parent
<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);