【问题标题】:android - how to update the theme not in the onCreate event?android - 如何更新不在 onCreate 事件中的主题?
【发布时间】:2012-08-09 02:48:04
【问题描述】:

在我的 android 应用程序中,我将主题设置为:

@Override
public void onCreate(Bundle savedInstanceState){
    ThemeSetterActivity.setStyle(Main_MenuActivity.this); // this just calls context.setTheme();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_menu);
}

但是如何使用

更改主题
ThemeSetterActivity.setStyle(Main_MenuActivity.this);

当它在 onresume 事件中时。当我尝试它时,它确实调用了该函数,但主题没有改变。是不是跟不叫有关系:

super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);

【问题讨论】:

    标签: android colors themes spinner


    【解决方案1】:

    要在运行时更改应用程序的主题,您可以在活动中使用setTheme(...) 方法。在加载该活动的视图之前,您必须将主题设置为活动。

    欲了解更多信息和实施,refer the link:

    更新

    并且,根据docs 设置主题,您需要重新启动整个活动。 您可以在活动的onResume() 中尝试此代码,

    Intent i = getIntent();
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多