Как открыть AlertDialog на полную ширину экрана - PullRequest
0 голосов
/ 02 июля 2018

Я хочу диалог, как показано ниже. this. Итак, я открыл активность как AlertDialog, а также использовал настраиваемое диалоговое окно оповещения. Код для Custom 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 голосов
/ 02 июля 2018

Это можно сделать двумя способами: сначала в 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. Добавить setlayout в 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();
...