我的应用程序有自定义布局的自定义偏好设置,在尝试在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"
,这应该使字体变大,但是我们会发现一个问题,如果使用相同的布局(只是没有seekbar),为什么标准偏好设置标题字体大小较小?