Background: I am using SwitchPreferenceCompat of the support preference v7 library by extending it as below in order to have more than one line for the Switch title:
public class MoreLinesSwitchPreference extends SwitchPreferenceCompat {
public MoreLinesSwitchPreference(Context context) {
super(context);
}
public MoreLinesSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MoreLinesSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
TextView textView = (TextView) holder.itemView.findViewById(android.R.id.title);
if (textView != null) {
textView.setSingleLine(false);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
}
}
}
My Preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="Settings">
<com.sed.al_mabadi_ul_mufeedah.MyCustomListPreference
android:defaultValue="20"
android:entries="@array/fontSize"
android:entryValues="@array/fontSize"
android:icon="@drawable/ic_format_size_24dp"
android:key="fontSize"
android:summary="20"
android:title="@string/settings_font_size" />
<com.sed.al_mabadi_ul_mufeedah.MyCustomListPreference
android:defaultValue="DroidNaskh-Regular"
android:entries="@array/font_face"
android:entryValues="@array/font_face"
android:icon="@drawable/ic_font_24dp"
android:key="fontFace"
android:summary="Choose Font Name"
android:title="@string/settings_font_name" />
<com.sed.al_mabadi_ul_mufeedah.MyCustomListPreference
android:defaultValue="en"
android:entries="@array/language"
android:entryValues="@array/language_short"
android:icon="@drawable/ic_language_24dp"
android:key="language"
android:summary="@string/app_restart"
android:title="@string/app_language_title" />
<com.sed.al_mabadi_ul_mufeedah.MoreLinesSwitchPreference
android:defaultValue="true"
android:icon="@drawable/ic_harakath_8b64ce_24dp"
android:key="diacriticsOn"
android:summary="@string/app_restart"
android:title="@string/show_hide_diacritics" />
<com.sed.al_mabadi_ul_mufeedah.MoreLinesSwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_night_24dp"
android:key="nightModeOn"
android:summary="@string/app_restart"
android:title="@string/settings_night_mode" />
<com.sed.al_mabadi_ul_mufeedah.MoreLinesSwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_screen_on"
android:key="alwaysOn"
android:summary="@string/sleep_on"
android:title="@string/settings_screen_on" />
</android.support.v7.preference.PreferenceScreen>
from my Compile dependencies:
compile 'com.android.support:preference-v7:24.2.0'
MyStyle.xml:
<style name="AppTheme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorControlActivated">@color/colorCursor</item>
<item name="colorControlHighlight">@color/colorFocus</item>
<item name="android:textColorPrimary">@color/colorPrimaryText</item>
<item name="android:textColorSecondary">@color/colorSecondaryText</item>
<item name="android:colorBackground">@color/background</item>
<item name="windowActionModeOverlay">true</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
Problem:
The SwitchPreferenceCompat is not animating between ON and OFF values.
I researched:
Why SwitchPreference is not showing animation when switching from on to off & vice versa?
Extending Preference classes in Android Lollipop = losing animation
https://code.google.com/p/android/issues/detail?id=185323
Why the above does not answer my question:
The above and other posts related to SwitchPreference does not speak about SwitchPreferenceCompat rather simply Switch or SwitchPreference
Need help in animating the switch between ON and OFF values.
Thanks for any help.