簡體   English   中英

Android DialogPreference寬度

[英]Android DialogPreference width

我有一個僅包含日期選擇器的自定義DialogPreference 除了對話框具有巨大的邊框和標題之外,其他所有內容都可以正常運行,如下所示。

在此處輸入圖片說明

我希望對話框只是日期選擇器:

在此處輸入圖片說明

我已經想出了如何通過將窗口標題設置為null來刪除標題的方法,但是大邊框仍然存在。

我的自定義布局:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <DatePicker 
        android:id="@+id/birthdayPicker"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center_horizontal"
        android:calendarViewShown="false"/>

</LinearLayout>

我試過將線性布局的width / height設置為wrap_content ,設置負邊距,以及其他許多hackey解決方案,但似乎沒有任何效果。

到目前為止,我唯一的運氣是重寫onShow並以編程方式將窗口大小設置為任意大小-例如300dp的寬度。 這顯然是超級騙子hackey,我希望有一個更優雅的解決方案。 任何幫助將不勝感激的家伙!

<?xml version="1.0" encoding="utf-8"?>

您的LinearLayout不應為match_parent而應為wrap_content例如DatePicker的尺寸。

嘗試:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <DatePicker 
        android:id="@+id/birthdayPicker"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center_horizontal"
        android:calendarViewShown="false"/>

</LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM