How to set a theme to whole application in code, but not in the Manifest?

前端 未结 6 1521
萌比男神i
萌比男神i 2020-12-16 17:11

I know how to set theme to whole application in manifest,but how to set theme to whole application programmatically ? I am trying this: getApplicationContext.se

6条回答
  •  情话喂你
    2020-12-16 17:50

    I use a custom activity for all activities in my application.

    Then I check a preference value in the onCreate of my inherited activity e.g.

    public class MyCustomActivity extends Activity {
    
    protected void onCreate(Bundle savedInstanceState) {
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(this);
            if(prefs.getBoolean("use_light_theme",false)==true)
            {
                setTheme(R.style.AppThemeLight);
            }
            super.onCreate(savedInstanceState);
    
    }
    

    //styles.xml

        
        
        
    

提交回复
热议问题