AlertDialog: How To Remove Black Borders Above and Below View

后端 未结 5 1719
难免孤独
难免孤独 2020-12-05 06:47

This question has been asked before: AlertDialog custom title has black border

But was not answered satisfactorily - and is missing some information.


I

5条回答
  •  -上瘾入骨i
    2020-12-05 07:44

    If you look at the AlertDialog class source you'll see most of the methods are simply proxy methods (facade) around private AlertController mAlert.

    Looking at the AlertController class source you'll see 4 interesting member variables:

    private int mViewSpacingLeft;
    private int mViewSpacingTop;
    private int mViewSpacingRight;
    private int mViewSpacingBottom;
    private boolean mViewSpacingSpecified = false;
    

    Setting mViewSpacingSpecified to true will remove the borders on the top and bottom of the dialog.

    This is done properly by changing this line:

    dialog.setView(layout);
    

    to:

    dialog.setView(layout, 0, 0, 0, 0);
    

提交回复
热议问题