Set theme color dynamically

后端 未结 5 1439
北荒
北荒 2020-12-14 23:31

I am using themes (dynamically) in my android app, like this:

my_layout.xml (extract):



        
5条回答
  •  悲&欢浪女
    2020-12-15 00:09

    What about passing theme id via Intent?

    Intent intent = new Intent(activity, MyActivity.class);
    intent.putExtra("theme", R.style.MainTheme_Green);
    activity.startActivity(intent);
    

    And then in onCreate:

    // assuming that MainTheme_Blue is default theme
    setTheme(getIntent().getIntExtra("theme", R.style.MainTheme_Blue));
    

提交回复
热议问题