我在通过更改应用程序设置中的偏好来以编程方式设置主题时遇到问题,我想在单击设置中的选项时在 Holo 和 Holo Light 之间切换。
任何建议,源代码,知识,链接等都表示赞赏,谢谢
仪表板活动.java
public class DashboardActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.onActivityCreateSetTheme(this);
setContentView(R.layout.dashboard_layout);
if (Settings.theme.equals("Theme1")) {
Utils.changeToTheme(this, Utils.THEME_LIGHT);
}else (Settings.theme.equals("Theme2")) {
Utils.changeToTheme(this, Utils.THEME_DARK);
}
设置.java
public class Settings extends PreferenceActivity implements
OnSharedPreferenceChangeListener {
public static String theme = "Theme1";
public void onBackPressed() {
// ListPreference listPreference2 = (ListPreference) findPreference("activityPref");
ListPreference listPreference = (ListPreference) findPreference("themePref");
String currValue = listPreference.getValue();
// String currValue2 = listPreference.getValue();
// Log.d("ssss", "Value :" + currValue);
// Log.d("ssss", "Value :" + currValue2);
// activity = currValue2;
theme = currValue;
super.onBackPressed();
设置.xml
<ListPreference
android:title="Themes"
android:summary="Change the UI of the application"
android:key="themePref"
android:entries="@array/themesReturnValue"
android:entryValues="@array/themesDisplayWord"
android:defaultValue="Theme1"/>
数组.xml
<string-array name="themesReturnValue">
<item>Light</item>
<item>Dark</item>
</string-array>
<string-array name="themesDisplayWord">
<item>Theme1</item>
<item>Theme2</item>
风格
<style name="LightThemeAndroid" parent="android:style/Theme.Holo.Light">
</style>
<style name="DarkThemeAndroid" parent="android:style/Theme.Holo">
</style>
这就是我得到的一切......我知道这是一项任务,但是任何帮助都非常感谢。谢谢