gpt4 book ai didi

Android PreferenceFragmentCompat 空格

转载 作者:行者123 更新时间:2023-11-29 00:59:48 31 4
gpt4 key购买 nike

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

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

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

有人知道怎么做吗?

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

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

最佳答案

我的解决方案是这样的:

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>

样式.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>

关于Android PreferenceFragmentCompat 空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52062902/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com