custom alert dialog getting unwanted padding

后端 未结 3 1591
甜味超标
甜味超标 2021-01-02 05:07

I have tried to make a custom alert dialog and it mostly works very well. the functionality is working perfectly but the view is behaving in a weird way. The dialog layout c

3条回答
  •  盖世英雄少女心
    2021-01-02 05:49

    Here is code that will give you full control over the dialog view:

    final Dialog dlg = new Dialog(this);
    View action_layout = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.contacts_action, null);
    dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);  
    Window window = dlg.getWindow();
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    WindowManager.LayoutParams wlp = window.getAttributes();
    wlp.gravity = Gravity.FILL_HORIZONTAL;
    window.setAttributes(wlp);
    dlg.setCancelable(true);
    dlg.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    dlg.setContentView(action_layout);
    dlg.show();
    

提交回复
热议问题