![](/img/trans.png)
[英]DialogFragment's width takes the whole screen unlike AlertDialog
[英]DialogFragment takes whole screen width
在我的Android應用程序中,我正在使用DialogFragment擴展類來顯示自定義對話框,但是我有一個問題,所有創建的對話框都占據整個屏幕寬度(照片中的示例),我希望它帶有邊距,該怎么做?
一種方法是使用樣式。 您可以創建自定義樣式,例如
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">@color/black</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:windowMinWidthMajor">80%</item>
<item name="android:windowMinWidthMinor">80%</item>
<!-- Used for the background -->
<item name="android:windowBackground">@color/white</item>
</style>
和DialogFragment
子類的onCreate
,您可以將其作為參數提供
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.AlertDialogStyle)
您可以在此處找到樣式中關鍵項目的描述
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.