Causes
I noticed that a few different things could cause the animation to go missing for my SwitchPreference
objects:
if the SwitchPreference
is the very first Preference
in the settings activity.
if I extend the SwitchPreference
and use that instead (post describing a similar problem).
Fixes
To avoid the first problem, I created a DummyPreference
class which I used as the first Preference
in the PreferenceScreen
instead. Examples below.
DummyPreference.java
public class DummyPreference extends Preference
{
public DummyPreference(Context context,AttributeSet attrs)
{
super(context,attrs);
}
@Override
public View getView(View convertView,ViewGroup parent)
{
View v = new View(getContext());
v.setVisibility(View.GONE);
return v;
}
}
pref_whatever.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.exaple.DummyPreference/>
<!-- other preference controls here -->
</PreferenceScreen>
To avoid the second problem, I had to just resort to using android's plain old Preference
classes in the XML, and I moved any extra logic needed into the Activity
or Fragment
containing the Preference
objects.
I know this is an old post. I'm just hoping that it may help someone else in the future.