Change Font Typeface Of Summary Of `listpreference`
I tried with THIS LINK to change the typeface of all preferences of PreferenceScreen. It was changed everywhere except summary of ListPreference. Can anyone has an idea how to appl
Solution 1:
Finally the way to change the font for summary of ListPreference
.
Override the onBindViewHolder
method of ListPreference
to set your custom typeface. Check below custom class.
publicclassCustomListPreferenceextendsListPreference {
private String typefaceTitle, typefaceSummary;
publicCustomListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
publicCustomListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
publicCustomListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
publicCustomListPreference(Context context) {
super(context);
}
@OverridepublicvoidonBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
if(!TextUtils.isEmpty(typefaceTitle)) {
TextViewtitleView= (TextView) holder.findViewById(android.R.id.title);
titleView.setTypeface(FontManager.getInstance().getFont(typefaceTitle));
}
if(!TextUtils.isEmpty(typefaceSummary)){
finalTextViewsummaryView= (TextView) holder.findViewById(
android.R.id.summary);
summaryView.setTypeface(FontManager.getInstance().getFont(typefaceSummary));
}
}
privatevoidinit(Context context, AttributeSet attrs){
TypedArraya= context.obtainStyledAttributes(attrs,
R.styleable.Preference);
typefaceTitle = a.getString(R.styleable.Preference_typefaceTitle);
typefaceSummary = a.getString(R.styleable.Preference_typefaceSummary);
a.recycle();
}}
attrs.xml
<declare-styleablename="Preference"><attrname="typefaceTitle"format="string"></attr><attrname="typefaceSummary"format="string"></attr></declare-styleable>
Usage in Preference screen.
<YOUR_CustomListPreference_PACKAGE_NAME.CustomListPreference
android:defaultValue="X"
android:dialogTitle="Dialog Title"
android:entries="@array/list_item_title"
android:entryValues="@array/list_item_value"
android:key="pref_list"
android:summary="%s"
android:title="@string/Preference Title"
app:typefaceTitle="YOUR FONT NAME"
app:typefaceSummary="YOUR FONT NAME"/>
Hope this help for other.
Solution 2:
try this
<!-- Base application theme. --><stylename="AppTheme"parent="Theme.AppCompat.Light.DarkActionBar"><!-- Customize your theme here. --><itemname="android:textAppearanceListItemSecondary">@style/textAppearanceListItemSecondaryCustom</item></style><stylename="textAppearanceListItemSecondaryCustom"><itemname="android:textSize">14sp</item><itemname="android:typeface">monospace</item></style>
Post a Comment for "Change Font Typeface Of Summary Of `listpreference`"