A theming library for Android
Switch branches/tags
Nothing to show
Clone or download
marverenic Update readme
Makes the preview image smaller and adds a note about new release versions
Latest commit bda5ae0 Aug 18, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
colors Add Javadocs Aug 18, 2017
gradle/wrapper Initial commit Apr 26, 2017
sample Update version name of sample app Aug 15, 2017
.gitignore Initial commit Apr 26, 2017
LICENSE Add readme and license Apr 28, 2017
README.md Update readme Aug 18, 2017
build.gradle Disable predex on Circle CI builds Jun 11, 2017
gradle.properties Initial commit Apr 26, 2017
gradlew Add execute permission to Gradle wrapper Jun 11, 2017
gradlew.bat Initial commit Apr 26, 2017
preview.gif Update readme Aug 18, 2017
settings.gradle Rename library module to colors Aug 8, 2017



Download CircleCI

Colors is a theming library for Android. It allows your app to use over 5,000 color combinations from the Material Design Palette by separately picking a primary and accent color.

Gradle Installation

dependencies {
    compile 'com.marverenic.colors:colors:1.x'

The latest version and release notes can be found on the Releases page.


Set a Theme

To use Colors, first set a global application theme. You need to do this before you show any themed Activities. A good place to set a default theme is in your Application class. You can set your theme with a single line of code:

Colors.setTheme(PrimaryColor.INDIGO_500, AccentColor.PINK_A200);

Theming an Activity

Colors only sets the primary and accent color of the theme, so build your activity as you normally would and give it a basic theme. To make Colors theme your activity, simply make your activity extend from either ColorsActivity or ColorsAppCompatActivity.

Colors will recreate your activity if the theme was changed when your activity is returned to. To immediately apply a theme, make sure you call recreate() in your Activity after calling Colors.setTheme(...).


Already extending from another library's Activity? No problem. Just create an instance of ColorsActivityDelegate in your Activity and call its onCreate and onResume methods as shown:

public class YourActivity extends Activity {
    private ColorsActivityDelegate delegate = new ColorsActivityDelegate(this);
    public void onCreate(Bundle savedInstanceState) {
        delegate.onCreate(); // Must be called before setContentView
        setContentView(/* Your layout resource */);
        // More initialization code for your Activity
    public void onResume() {

User Theme Preferences

Colors doesn't provide a built-in way to offer the user a theme choice. Developers can build any interface to present to the user and add any number of constraints to which themes can be built.

Colors also does not save the last chosen theme automatically. If you're using SharedPreferences, however, you can easily save the theme:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
PrimaryColor primaryColor = PrimaryColor.INDIGO_500;
AccentColor accentColor = AccentColor.PINK_A200;

    .putString(PRIMARY_COLOR_PREF_KEY, primaryColor.getId())
    .putString(ACCENT_COLOR_PREF_KEY, accentColor.getId())

And restore it just as easily:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
PrimaryColor defaultPrimary = PrimaryColor.INDIGO_500;
AccentColor defaultAccent = AccentColor.PINK_A200;

PrimaryColor primaryColor = PrimaryColor.findById(
        prefs.getString(PRIMARY_COLOR_PREF_KEY, defaultPrimary.getId()));

AccentColor accentColor = AccentColor.findById(
        prefs.getString(ACCENT_COLOR_PREF_KEY, defaultAccent.getId()));

Colors.setTheme(primaryColor, accentColor);