我做了一个SwitchPreference
对于我的应用程序preferences
.
问题是SwitchPreference
当我在打开和关闭之间切换时,它没有显示动画,而是突然猛烈地切换。
Here's preferences.xml
文件的代码:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:id="@+id/notification"
android:key="notification"
android:title="@string/notification"
android:defaultValue="true"/>
</PreferenceScreen>
Causes
我注意到一些不同的事情可能会导致我的动画丢失SwitchPreference
对象:
if the SwitchPreference
是第一个Preference
在设置活动中。
如果我延长SwitchPreference
并使用它来代替(描述类似问题的帖子).
Fixes
为了避免第一个问题,我创建了一个DummyPreference
我用作第一个类Preference
in the PreferenceScreen
反而。下面的例子。
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>
为了避免第二个问题,我不得不求助于使用 android 的普通旧版Preference
XML 中的类,并且我将所需的任何额外逻辑移至Activity
or Fragment
含有Preference
对象。
我知道这是一个旧帖子。我只是希望它将来可以帮助别人。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)