【问题标题】:Android PreferenceFragmentCompat blank spaceAndroid PreferenceFragmentCompat 空格
【发布时间】:2018-08-28 16:52:32
【问题描述】:

我正在使用 PreferenceFragmentCompat(来自 'com.android.support:preference-v7:28.0.0-rc02')来创建设置菜单。

问题是我在每个项目的左侧都有一个黑色空间:

我通过为每个选项添加图标“解决”了这个问题,但我希望 PreferenceCategory 的标题左对齐

有人知道怎么做吗?

你可以在这里看看我的布局:https://github.com/systemallica/ValenBisi/blob/master/app/src/main/res/xml/fragment_settings.xml

我尝试使用android:iconSpaceReserved="false",但没有任何区别。

【问题讨论】:

  • 你解决了吗?
  • 不是,不是。我找不到解决方案。

标签: android fragment android-support-library preferences


【解决方案1】:

我的解决办法是这样的:

custom_preference_category_material.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="?android:attr/listPreferredItemPaddingLeft"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@android:id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="start"
            android:paddingRight="?android:attr/listPreferredItemPaddingRight"
            android:textAlignment="viewStart"
            android:textColor="?colorAccent" />

        <TextView
            android:id="@android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:singleLine="true"
            android:textColor="?android:attr/textColorSecondary" />
    </LinearLayout>

</FrameLayout>

styles.xml

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

<style name="CustomPreferenceTheme" parent="@style/PreferenceThemeOverlay">
    <item name="preferenceCategoryStyle">@style/CustomPreferenceCategory</item>
    <item name="preferenceStyle">@style/CustomPreference</item>
    <item name="checkBoxPreferenceStyle">@style/CustomCheckBoxPreference</item>
    <item name="dialogPreferenceStyle">@style/CustomDialogPreference</item>
    <item name="switchPreferenceCompatStyle">@style/CustomSwitchPreferenceCompat</item>  <!-- for pre lollipop(v21) -->
    <item name="switchPreferenceStyle">@style/CustomSwitchPreference</item>
    <item name="seekBarPreferenceStyle">@style/CustomSeekBarPreference</item>
    <item name="preferenceScreenStyle">@style/CustomPreferenceScreen</item>
</style>

<style name="CustomPreferenceCategory" parent="Preference.Category.Material">
    <item name="android:layout">@layout/custom_preference_category_material</item>
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomPreference" parent="Preference.Material">
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomCheckBoxPreference" parent="Preference.CheckBoxPreference.Material">
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomDialogPreference" parent="Preference.DialogPreference.Material">
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomSwitchPreferenceCompat" parent="Preference.SwitchPreferenceCompat.Material">
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomSwitchPreference" parent="Preference.SwitchPreference.Material">
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomSeekBarPreference" parent="Preference.SeekBarPreference.Material">
    <item name="iconSpaceReserved">false</item>
</style>

<style name="CustomPreferenceScreen" parent="Preference.PreferenceScreen.Material">
    <item name="iconSpaceReserved">false</item>
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    相关资源
    最近更新 更多