如何改变当前的主题在运行时的Andr​​oid [英] How to change current Theme at runtime in Android

查看:162
本文介绍了如何改变当前的主题在运行时的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个preferenceActivity,允许用户选择他想要应用到整个应用程序的主题。

I've created a PreferenceActivity that allows the user to choose the theme he wants to apply to the entire application.

当用户选择一个主题,code执行:

When the user selects a theme, this code is executed:

if (...) {
    getApplication().setTheme(R.style.BlackTheme);
} else {
    getApplication().setTheme(R.style.LightTheme);
}

不过,即使我已经与正在执行的code中的调试器检查,我看不到在用户界面中的任何变化。

But, even though I've checked with the debugger that the code is being executed, I can't see any change in the user interface.

主题在 RES /价值/ styles.xml ,定义和Eclipse没有显示任何错误。

Themes are defined in res/values/styles.xml, and Eclipse does not show any error.

<resources>
    <style name="LightTheme" parent="@android:style/Theme.Light">
    </style>

    <style name="BlackTheme" parent="@android:style/Theme.Black">
    </style>    
</resources>

什么可能会发生,以及如何解决它的主意? 我应该叫 setTheme 在在code什么特殊意义呢?我的应用程序由几个活动是否有帮助。

Any idea about what could be happening and how to fix it? Should I call setTheme at any special point in the code? My application consists of several Activities if that helps.

推荐答案

我想看到的方法也一样,在这里您将一劳永逸的活动。不过,据我知道你表现出任何意见之前,每个活动设置。

I would like to see the method too, where you set once for all your activities. But as far I know you have to set in each activity before showing any views.

有关引用检查:

<一个href="http://www.anddev.org/applying_a_theme_to_your_application-t817.html">http://www.anddev.org/applying_a_theme_to_your_application-t817.html

这篇关于如何改变当前的主题在运行时的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆