开发者

how can we dynamically switch on or off from one Theme to another Theme for whole activity

how can we dynamically switch on or off from one Theme to another Theme for whole application...i have try to find everywhere b开发者_运维知识库ut cant get success.....so,please provide any source code...


setTheme() does work, you just have to be sure to set the theme before any of the system framework starts building views. I have applications that can switch themes on the fly but you must call setTheme() first in your onCreate() method:

@Override
protected void onCreate(Bundle savedInstanceState) {

    // The only way the custom themes apply properly is to assign them before any view
    // resources are created.
    SettingsActivity.setThemeFromPreferences(this);

    super.onCreate(savedInstanceState);
}

Where the setThemeFromPreferences method looks up the setting and calls setTheme with the appropriate style. Also take a look at Ben's answer to this post about restarting an activity that you may want to use to apply your theme changes on the fly after they are changed by the user.


You can try with setTheme, but you might run into monsters.


There is an open Google Android issue for this: it appears to be an open bug that you cannot programmatically change the theme with setTheme(). http://code.google.com/p/android/issues/detail?id=4394

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜