How to set margins to a custom dialog?

前端 未结 15 1228
再見小時候
再見小時候 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:32

    you could make a new shape drawable resource and set color of it transparent :

    
    
        
    
    

    then you can add these simple lines in your dialog class onCreate method :

    getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);  
    getWindow().setBackgroundDrawableResource(R.drawable.drawble_resource_you_made_before);
    

    don't forget to put your dialog layout resource background white or any color you want then you could easily by editing your dialog layout resource and customize it :)

提交回复
热议问题