我有一个更改动画持续时间的代码,首先启动程序“preferenze”运行以读取 sharedpreferences,稍后,用户可以通过 Preferences.class 更改动画持续时间。似乎还可以,但我无法更新首选项,我的代码:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// 每次应用启动时运行
preferenze();
// 读取共享私有 void preferenze() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
CheckboxPreference = prefs.getBoolean("checkboxPref", true);
String ListPreference = prefs.getString("listpref", "1500");
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Impostazioni").setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//Toast.makeText(getApplicationContext(), "Vai al Racconto... Non attivo", Toast.LENGTH_SHORT).show();
//goToPage();
Intent settingsActivity = new Intent(getBaseContext(),
Preferences.class);
startActivity(settingsActivity);
public void onSharedPreferenceChanged(SharedPreferences prefs,
String listpref) {
Toast.makeText(getApplicationContext(), "eseguo changed: "+listpref, Toast.LENGTH_SHORT).show();
if (fade == 500){
animazione = R.style.MyCustomTheme1;
}
else if (fade == 1000){
animazione = R.style.MyCustomTheme2;
}
else if (fade == 1500){
animazione = R.style.MyCustomTheme3;
}
else if (fade == 2000){
animazione = R.style.MyCustomTheme4;
}
}
显现:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />