Colors


Source link: https://github.com/marverenic/Colors

Colors

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.

Usage

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(...).

ColorsActivityDelegate

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);

 @Override
  public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

delegate.onCreate();
 // Must be called before setContentView

setContentView(/* Your layout resource */);

// More initialization code for your Activity
  
}

 @Override
  public void onResume() {

super.onResume();

delegate.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;  prefs.edit()
  .putString(PRIMARY_COLOR_PREF_KEY, primaryColor.getId())
  .putString(ACCENT_COLOR_PREF_KEY, accentColor.getId())
  .apply();

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);

Resources

Easy Android form validation in Rx way.

This library can be used to implement Material Designed Settings/Preference Screen on Pre-Lollipop devices.

A clean, minimalistic, easy-to-use and highly customizable pin lock custom view for Android.

HintCase is a library for Android that will help you create really awesome hints/tips for your apps.

AdvancedTextView provides advanced features that simplifies complicated UI processes.

This android library lets you persist the state of your views to recover them later in order to display old data until fresh data arrives.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes