如何删除首选项标题和以下首选项之间的填充?

How to remove the padding between preference title and the following preference?

我想删除我的首选项屏幕中的紫色间隙: preference

所以它应该是这样的: Google Play Store example

我正在使用 Xamarin Android 和 c# 来开发我的应用程序。 首选项屏幕是来自 Android.Support.V7.Preferences 库的 PreferenceFragmentCompat。 material 样式在我的自定义主题中设置:

<style name="Theme.DarkTheme" parent="Theme.AppCompat.NoActionBar">
   <item name="colorPrimary">#673AB7</item>
   <item name="colorPrimaryDark">#512DA8</item>
   <item name="colorAccent">#039be5</item><!--#FF4081-->
   <item name="colorControlHighlight">#242424</item>
   <item name="android:listDivider">@style/android:drawable/divider_horizontal_dim_dark</item> 
   <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item> 

这是我的 xml 资源文件的样子,我在 PreferenceFragmentCompats OnCreatePreferences() 函数中通过 AddPreferencesFromResource(Resources.Id.preference_screen) 调用它:

<android.support.v7.preference.PreferenceScreen 
   xmlns:android="http://schemas.android.com/apk/res/android">
   <android.support.v7.preference.PreferenceCategory
    android:title="App">
        <Preference
            android:key="advsettings_preference"
            android:title="Erweiterte Einstellungen" />
        <Preference
            android:key="license_preference"
            android:title="Rechtliche Hinweise" />
   </android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>

我已经尝试通过向 PreferenceScreen 添加填充属性来自行修复它,但没有任何改变。

来自 Xamarin Android 的所有最新 NuGet 包已安装 (v27.0.2)。 提前致谢。

在开发者选项中启用 "use layout bounds" 查看您的布局时,紫色区域表示边距,据我所知不是填充。

我建议尝试为您的 PreferenceCategoryPreference 制作自定义布局,并使用 android:layout 属性将它们设置在上面的 axml 中:

android:layout="@layout/layout_name"

(可能需要同时使用两个 android:layout and android:widgetLayout 属性)

请尝试这样设置样式;

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    ...
    <!-- Customize your theme here. -->
    <item name="preferenceTheme">@style/MyPreferenceStyle</item>
</style>

<style name="MyPreferenceStyle" parent="@style/PreferenceThemeOverlay.v14.Material">
    <item name="preferenceCategoryStyle">@style/MyPreferenceCategoryStyle</item>
    <item name="android:paddingLeft">10dp</item>
    <item name="android:paddingRight">10dp</item>
</style>

<style name="MyPreferenceCategoryStyle" parent="@style/Preference.Category.Material">
    <item name="android:layout">@layout/preference_category</item>
</style>

preference_category.axml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+android:id/title"
    android:textColor="?android:attr/colorAccent"
    android:textSize="14dp"
    android:fontFamily="sans-serif-medium"
    android:paddingStart="16dp"
    android:singleLine="true"
    android:paddingTop="16dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

和 AppSettings:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">
    <android.support.v7.preference.PreferenceCategory
        android:title="App">
        <Preference
            android:key="advsettings_preference"
            android:title="Erweiterte Einstellungen"
            android:summary="BenachRichtigung"/>
    </android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>

它将解决差距问题。而且看起来也类似于 Google Play 商店的屏幕截图。好吧,与 Layout Inspector 不完全相同,但相似: