Android: Как настроить Margin / Padding в настройках? - PullRequest
14 голосов
/ 03 марта 2012

Прежде чем я попросил удалить отступы PreferenceActivity / PreferenceFragment:

Android: как увеличить ширину PreferenceFragment (или избавиться от наценки)?

На этот раз у меня возникли проблемы с настройкой полей / отступов перед текстом заголовка. (См. Изображение ниже).

enter image description here

У кого-нибудь есть идеи?

Ответы [ 4 ]

10 голосов
/ 28 марта 2014

Для тех, кто сталкивается с этой проблемой и не хочет проходить пользовательский макет. Хочу отметить, что добавление:

android:icon="@null"

решил мою проблему с пустым пространством слева.

<PreferenceScreen android:icon="@null" android:title="Your title" android:summary="Your summary" />
10 голосов
/ 06 июля 2012

Вы можете настроить свой флажок следующим образом: MyPreference.xml

<CheckBoxPreference android:key="testcheckbox" 
    android:title="Checkbox Title" 
    android:summary="Checkbox Summary..." 
    android:layout="@layout/custom_checkbox_preference_layout">
</CheckBoxPreference>

и custom_checkbox_preference_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingLeft="16dip"
    android:paddingRight="?android:attr/scrollbarSize">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minWidth="0dp"
        android:gravity="center"
        android:orientation="horizontal">
        <ImageView
            android:id="@+android:id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="6dip"
        android:layout_marginTop="6dip"
        android:layout_marginBottom="6dip"
        android:layout_weight="1">

        <TextView android:id="@+android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal" />

        <TextView android:id="@+android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/title"
            android:layout_alignLeft="@android:id/title"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="4" />

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@+android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" />

</LinearLayout>

точка - android: minWidth = "0dp".

0 голосов
/ 12 декабря 2016

Если вы создаете настройки, динамически передайте ContextThemeWrapper в качестве параметра новой настройке

TypedValue themeTypedValue = new TypedValue();
getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, themeTypedValue, true);
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getActivity(), themeTypedValue.resourceId);
Preference preference = new Preference(contextThemeWrapper);

Я нашел это в этой статье: Динамическое создание экранов настроек на Android

0 голосов
/ 12 октября 2014

custom_checkbox_preference_layout.xml, описанный user1482130, работает также без изменений для других типов предпочтений, таких как listpreferences!Очень полезно

android:layout="@layout/custom_checkbox_preference_layout">
...