Regarding @Joaquim Ley's answer, we can change the theme to super.onCreate() .
In my application (at work) my styles.xml :
This is my default theme.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="android:colorAccent">@color/colorPrimary</item> <item name="android:statusBarColor">@color/colorPrimaryDark</item> <item name="android:colorFocusedHighlight">@color/colorPrimary</item> <item name="android:colorControlNormal">@color/amber_300</item> <item name="android:colorControlActivated">@color/amber_300</item> <item name="android:colorControlHighlight">@color/colorControlHighlight</item> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> <item name="android:windowTranslucentStatus">false</item> <item name="actionBarItemBackground">?attr/selectableItemBackground</item> <item name="colorControlHighlight">@color/colorControlHighlight</item> <item name="android:windowContentTransitions">true</item> </style>
And this is my green topic:
<style name="AppTheme.Green" parent="AppTheme"> <item name="colorPrimary">@color/green_500</item> <item name="colorPrimaryDark">@color/green_700</item> <item name="android:colorAccent">@color/green_300</item> <item name="android:statusBarColor">@color/green_700</item> <item name="android:colorFocusedHighlight">@color/green_500</item> <item name="android:colorControlNormal">@color/green_300</item> <item name="android:colorControlActivated">@color/green_300</item> </style>
When changing the topic:
@Override protected void onCreate(Bundle savedInstanceState) { mPrefs=getSharedPreferences(getResources().getString(R.string.preference_name),MODE_PRIVATE); mEditor=mPrefs.edit(); mEditor.apply(); defaultColor=mPrefs.getInt(getResources().getString(R.string.default_color),0); //you can do some switch case or if else of defaultColor and change theme setTheme(R.style.AppTheme_Green); super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_voice_record); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); }
This is my first application to work, but in my personal application I created BaseActivity and created the handleColor(int color,int darkcolor) . But this will not change the whole theme of only the Toolbar , StatusBar , NavigationBar and EditText marker and underline colors:
public class BaseActivity extends AppCompatActivity { public void handleColor(int color,int darkcolor){
When changing color, I use Color Dialer. Apk example: sample.apk and Github : material-dialogs . If you want to see how it looks, I can give you a video of my application.
Colors: Material color palette
Anyway, I know 2 different approaches, if you like one of them, I can explain more.
@Edit : Good news for you, I found this rehearsing Github: app-theme-engine and its work is good. You can try the sample apk. If you cannot import it through gradle, try this: compile 'com.github.naman14:app-theme-engine: 0.5.1@aar '