How to set margins to a custom dialog?

前端 未结 15 1208
再見小時候
再見小時候 2020-12-05 05:56

Does anybody knows how can I set margins to a custom dialog? I\'m asking because I\'ve a custom dialog but when displayed it stretches to fill the parent, even though I set

15条回答
  •  旧巷少年郎
    2020-12-05 06:40

    I was having trouble with the other solutions presented as the "OK" and "CANCEL" buttons went outside of the screen and it just looked weird. Instead, I used android:windowMinWidthMinor & android:windowMinWidthMajor which looked better and incidentally also required less code. Nothing is needed in Java / Kotlin.

    Here's all I did:

    1) Only use only one background drawable (I called mine dialog_box.xml)

    
    
        
        
    
    

    2) Set background in Layout:

    
    
    
    
    

    3) Set style:

        @style/AlertDialogTheme
    
        
    

提交回复
热议问题