更改和应用的主题在运行时的Andr​​oid [英] Change and apply theme at runtime in Android

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

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android">How要改变目前的主题在运行时的Andr​​oid

我有一个Android应用程序,我允许用户在运行时主题之间切换。切换主题是容易的,但<一个href="https://developer.android.com/reference/android/view/ContextThemeWrapper.html#setTheme%28int%29">the主题不会应用,直到活动被重建。我找到了一种方法<一href="http://stackoverflow.com/questions/9446193/theme-programmatically-set-how-to-reload-activity-to-apply">apply主题为当前活动但如果用户presses后退按钮previous屏幕仍然有旧的主题。如何更改主题为这些活动?应用实例支持它:任务免费

I have an Android application where I allow users to switch between themes at runtime. Switching a theme is easy but the theme isn't applied until the activity is recreated. I found a way to apply the theme to current activity but if the user presses back button previous screens still have the old theme. How can I change theme for those activities? Example of app that supports it: Tasks Free

推荐答案

在运行时动态,调用setTheme()在活动的onCreate()方法,调用的setContentView()之前。要更改主题,你只需要重新启动您的活动。

Dynamically at runtime, call setTheme() in your activity's onCreate() method, before calling setContentView(). To change the theme, you simply need to restart your activity.

请参阅这个文件..!

也想看看和< A HREF =htt​​p://www.anddev.org/applying_a_theme_to_your_application-t817.html相对=nofollow>这个 ... 希望这有助于...!

Also Want see this and this ... Hope this helps...!

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

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