我正在尝试在应用程序中进行设置,特别是 ListPreference 以便能够更改应用程序的背景动画,但我不能这样做,如果您选择选项 1 或选项 2,则没有任何变化......我遵循了类似的教程并试图让它对我有用,但到目前为止还没有。这里是java
SharedPreferences backChooser = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String values = backChooser.getString("list", "1");
img = (ImageView) findViewById(R.id.imageView1);
img.setBackgroundResource(R.drawable.anim1);
animation = (AnimationDrawable) img.getDrawable();
animation.start();
if (values.contentEquals("1")) {
img.setBackgroundResource(R.drawable.anim1);
animation = (AnimationDrawable) img.getDrawable();
animation.start();
}
if (values.contentEquals("2")) {
img.setBackgroundResource(R.drawable.anim2);
animation = (AnimationDrawable) img.getDrawable();
animation.start();
}
这是首选项的xml
<?xml version="1.0" encoding="utf-8"?>
<ListPreference
android:entries="@array/list"
android:entryValues="@array/listvalues"
android:key="list"
android:summary="This is a list to choose from"
android:title="List" />