Che*_*ter 38 android themes android-theme
我试图获得一个用户选择的主题,感觉我很沮丧.在AndroidManifest.xml
工作中定义主题应该是,但(尽我所知)不能根据应用程序首选项更改:
<application
android:theme="@style/theme_sunshine"
android:icon="@drawable/icon"
android:label="@string/app_name">
Run Code Online (Sandbox Code Playgroud)
或者,在每个活动中动态设置它也可以:
someChosenTheme = PreferenceManager.getDefaultSharedPreferences(this).getString("themePreference", "theme_twilight");
setTheme(someOtherChosenTheme);
Run Code Online (Sandbox Code Playgroud)
但这看起来很混乱,我宁愿在一个地方设置整个应用程序的主题.我的第一个想法是在我的主要活动启动并在那里执行时抓住应用程序上下文:
getApplicationContext().setTheme(R.style.theme_dummy);
Run Code Online (Sandbox Code Playgroud)
我可以说,这应该是诀窍,但实际上它没有做任何事情 - 整个应用程序都有默认的Android风格.以上是否有效,如果是的话,我可能会做一些其他的愚蠢行为吗?
如果重要的话,我在API级别3工作.正确方向的产品非常感谢!
pet*_*er3 31
为您的应用创建基本活动并覆盖onCreate以设置主题.从此基本活动中派生所有其他活动.
另请查看本教程:http: //www.androidengineer.com/2010/06/using-themes-in-android-applications.html
可能有一个很好的解决方案,但我找不到一个,所以我最终在一个辅助类中创建一个小的静态辅助方法,它接受一个Activity并基本上执行你编写的那两行.当然,它并不完美,但只需onCreate()
在我的应用程序中为每个方法添加一行简短的代码就可以忍受了.
归档时间: |
|
查看次数: |
31880 次 |
最近记录: |