自定义首选项标题字体大小大于android 5中的标准首选项

时间:2014-11-22 12:20:33

标签: android android-preferences android-5.0-lollipop

我的应用程序具有自定义布局的自定义首选项,在Android 5上尝试我的应用程序后,我注意到我的自定义首选项看起来与其他首选项不同(字体大小,颜色,填充)。所以我认为只需从android 5 SDK中获取preference.xml,与我的更改合并并将新布局放到layout-v21文件夹即可。它修复了填充和颜色问题,但没有更大的标题大小。

我的自定义首选项构造函数如下所示:

public SeekBarPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    setLayoutResource(R.layout.preference_seekbar);
}

preference_seekbar.xml(刚刚将Seekbar添加到原始布局):

<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:paddingEnd="?android:attr/scrollbarSize"
    android:background="?android:attr/selectableItemBackground" >

    <ImageView
        android:id="@+android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dip"
        android:layout_marginEnd="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/textAppearanceLarge"
            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_alignStart="@android:id/title"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="4" />

        <SeekBar android:id="@+id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+android:id/title"
            android:layout_toEndOf="@android:id/summary"
            android:layout_toStartOf="@android:id/widget_frame"/>

    </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_vertical"
        android:orientation="vertical" />

</LinearLayout>

你可以注意到上面的标题小部件有这个原始属性:android:textAppearance="?android:attr/textAppearanceLarge"它应该使字体变大,但是如果标准首选项标题字体大小使用相同的布局(只有没有搜索条),那么有一个问题)?

1 个答案:

答案 0 :(得分:1)

遇到同样的问题,找到solution here

虽然我使用textAppearanceListItem作为标题TextView,因为它似乎更适合我。

<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:paddingStart="?attr/listPreferredItemPaddingStart"
    android:paddingEnd="?attr/listPreferredItemPaddingEnd">

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

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dip"
        android:layout_marginEnd="8dip"
        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_alignStart="@android:id/title"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary"
            android:maxLines="4" />

        <!-- 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:layout_below="@android:id/summary"
            android:layout_alignStart="@android:id/title"
            android:minWidth="@dimen/preference_widget_width"
            android:gravity="center"
            android:orientation="vertical" />

        <SeekBar android:id="@+android:id/seekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@android:id/summary"
            android:layout_toEndOf="@android:id/widget_frame"
            android:layout_alignParentEnd="true" />

    </RelativeLayout>

</LinearLayout>
相关问题