大家好我是android開發的新手。我想在用戶在首選activity.i列表首選項中選擇任何主題時打開一個警告對話框。我在谷歌搜索很多,但沒有找到任何適當的答案。我的PrefenceActivity。在列表首選項中單擊項目時顯示警告對話框-ios
public class Setting extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Setting.setAppTheme(this);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
String ListPreference;
public static void setAppTheme(Activity a) {
// Get the xml/preferences.xml preferences
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(a);
int ListPreference = Integer.parseInt(prefs.getString("listPref", "3"));
if(ListPreference == 0) {
a.setTheme(R.style.AppBaseThemeDark);
return;
} else if(ListPreference == 1){
a.setTheme(R.style.AppBaseThemeLight);
//Toast.makeText(getApplicationContext(),"TTS Engines not found.\n Install TTS Engins",Toast.LENGTH_LONG).show();
} else if(ListPreference == 2){
a.setTheme(R.style.AppBaseTheme);
}
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getActionBar().setDisplayHomeAsUpEnabled(true);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
getFragmentManager().popBackStack();
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}
出色的作品很棒 – user2837584
很高興能幫到:) –
當我說這個課程是嵌套在我原來的課程中的時候,我似乎無法正常工作。有小費嗎? –