【发布时间】:2011-06-07 12:25:43
【问题描述】:
我正在尝试获取用户选择的主题,并且感觉自己非常接近。在AndroidManifest.xml 中定义主题可以正常工作,但(据我所知)不能根据应用偏好进行更改:
<application
android:theme="@style/theme_sunshine"
android:icon="@drawable/icon"
android:label="@string/app_name">
另外,在每个活动中动态设置它也可以:
someChosenTheme = PreferenceManager.getDefaultSharedPreferences(this).getString("themePreference", "theme_twilight");
setTheme(someOtherChosenTheme);
但这看起来很乱,我宁愿将整个应用程序的主题设置在一个地方。我的第一个想法是在我的主要活动启动后立即获取应用程序上下文并在那里执行:
getApplicationContext().setTheme(R.style.theme_dummy);
据我所知,this 应该可以解决问题,但实际上它什么也没做 - 整个应用程序具有默认的 Android 样式。以上是否有效,如果是,我可能会做其他愚蠢的事情吗?
如果这很重要,我正在使用 API 级别 3。非常感谢您朝着正确的方向前进!
【问题讨论】:
标签: android themes android-theme