Android - ListPreference 对话框没有填充或边距

Android - ListPreference dialog has no padding or margins

我已经设置了一个带有键、标题和条目等的 ListPreference。在 XML 中看起来像这样:

<ListPreference
        android:key = "@string/pref_currency"
        android:title="@string/settings_currency_title"
        android:dialogTitle="@string/settings_currency_title"
        android:entries="@array/locale_entries"
        android:entryValues="@array/locale_entry_values"/>

它带有 PreferenceScreen。

当我在我的应用程序中通过单击打开 ListPreference 时,它​​看起来像这样:

我为我的应用程序使用的主题如下:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
    <item name="android:textColorPrimary">@color/primary_text</item>
    <item name="android:textColorSecondary">@color/secondary_text</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">true</item>
    <item name="android:fitsSystemWindows">true</item>
</style>

我原以为标题和取消按钮周围会有一些边距或填充。有人知道为什么没有吗?是不是默认就这么丑?

此外,有人知道我如何为标题和取消按钮添加一些填充吗?

问题出在您的 styles.xml 文件中。如果您从主题中排 <item name="android:fitsSystemWindows">true</item> 或将其值设置为 false,一切都会按预期工作。

android:fitsSystemWindows

Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.