My app has custom preference with custom layout and after trying my app on android 5, I noticed that my custom preferences look different (font size, color, padding) than the others. So I thought it would be an easy fix just taking preference.xml
from android 5 SDK, merging with my changes and placing a new layout to layout-v21
folder. It fixed padding and color issues, but not size of the title which is bigger.
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 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 can notice above that title widget has this original attribute: android:textAppearance="?android:attr/textAppearanceLarge"
which should make font large, but then there is a question why standard preference title font size is smaller if it uses the same layout (only without seekbar)?
Titles on mobile Material Design apps are 20sp. The body text size in Material Design is 14sp. You should think of this as the normal font size, and basically everything else a variation on it. For instance, while 14sp is the default text size when the text can be quite long, when there’s only a small modal with a bit of text, it’s 16sp!
But, it does allow you to change the font size. To change it go to: Use the slider at the bottom to make the font as big or as small as you want. An app that will give you various font style options is the Font – Stylish Text & Cool Fonts app.
Even though you can’t change the font style in Oreo, at least you can change the font size. Android Oreo doesn’t allow any integrated default setting to change the font style. But, it does allow you to change the font size.
Reason being your layout might different in style (size, margin, etc.) from other preference. If possible, you should create a custom layout without overriding the layout (e.g. Android Preference With Icon On Right Side of Title ) Content of R.layout.preference_pro_switch. Example of Preference layout
Had the same issue, found the solution here.
Although I used textAppearanceListItem
for the title TextView
as it seems a better fit 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With