custom alert dialog getting unwanted padding

后端 未结 3 1592
甜味超标
甜味超标 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

    For me, it seemed that builder.setView(dialogView, 0, 0, 0, 0); is set to @hide and not available. In the end, I had to set the padding of my custom view's parent after calling show()

    For example:

    // Inflate custom dialog view
    LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    CustomDialogView dialogView = (CustomDialogView)inflater.inflate(R.layout.dialog_view, null);
    
    // Create and show custom alert dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.dialog_title);
    builder.setView(dialogView);
    builder.setPositiveButton(R.string.dialog_ok, this);
    builder.setNegativeButton(R.string.dialog_cancel, this);
    builder.show();
    
    // Remove padding from parent
    ViewGroup parent = (ViewGroup)dialogView.getParent();
    parent.setPadding(0, 0, 0, 0);
    

提交回复
热议问题