Custom preference font size is larger than standard preference in android 5

My application has user preferences with a custom layout, and after trying my application on Android 5, I noticed that my user settings look different (font size, color, padding) than others. So I thought it would be a simple fix, just taking the preference.xml from the android 5 SDK SDK, merging with my changes and putting the new layout in the layout-v21 . He fixed fill and color problems, but not the size of the header, which is larger.

My custom preference constructor looks like this:

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

preference_seekbar.xml (just added by Seekbar to the original layout):

 <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> 

You may notice that this header widget has this original attribute: android:textAppearance="?android:attr/textAppearanceLarge" , which should make the font large, but the question arises why the font size of the standard font is smaller if it uses the same layout ( only without a search box)?

+5
source share
1 answer

Had the same problem, found a solution here.

Although I used textAppearanceListItem for the TextView title, it seems to me to be better suited to me.

 <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> 
+1
source

Source: https://habr.com/ru/post/1207473/


All Articles