MaterialDesignSpecs


Source link: https://github.com/androidessence/MaterialDesignSpecs

Material Design Specs Library

This library provides an easy and quick way to access the entire material design color palette and elevation values, along with some neat helper methods like random access to material design colors.

Usage

To have access to the library, add the dependency to your build.gradle:

 implementation 'com.androidessence:materialdesignspecs:2.0.1'

At the time of publication, the library has not yet been linked to JCenter, so you will also have to add the link to our Maven repository as well:

 repositories {

maven {

 url  "http://dl.bintray.com/androidessence/maven"

}
  
}

Now, you'll be able to access the full color pallete from material design, either by XML, or programatically.

  • XML way
 <!-- You can use it in any view or other XML resources -->  <!-- Access the resources by using @color/ or @dimen/ -->  <View

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@color/mds_red_500"

android:elevation="@dimen/mds_elevation_card_resting"/>
  • Java way
 // Access it through the android R file. Like the examples below.  R.color.mds_red_500  R.color.mds_blue_700  R.color.mds_pink_A100  R.color.mds_indigo_200  // Elevations  R.dimen.mds_elevation_card_resting  R.dimen.mds_elevation_dialog  R.dimen.mds_elevation_navigation_view  R.dimen.mds_elevation_menu

You'll also have access to some static helper methods like:

 getColorsByName(String colorName) // Returns a List<Integer> of colors with the given name.  // The methods below returns an Integer to use along your code.  getRandomColor()  getRandomNonAccentColor()  getRandomColorByLevel(String colorLevel)  getRandomColorByName(String colorName)  getRandomColorNonRepeating()  // And a few more!

To specify a color name or level, use the available static strings such as:

 MaterialPalettes.RED
  MaterialPalettes.LEVEL_500

Please be aware that the Integer returned by the methods above is the Integer of the resource identifier, not the color itself. So, in order to give a TextView a random text color, it would be done like this:

 Integer randomColor = MaterialPalettes.getRandomColor();
  myTextView.setTextColor(getResources().getColor(randomColor));

ColorPicker

MDS also supplies a built in ColorPicker dialog you can use to allow users to pick a color. There's both a circle and a square color adapter you can use, and also a base one you can implement to make your own. Supply an adapter and a list of colors for the picker, as well as implement an OnColorSelectedListener interface to use it. Here is an example usage of the dialog:

 try {

ColorDialog colorDialog = ColorDialog.newInstance(MaterialPalettes.getColorsByLevel(MaterialPalettes.LEVEL_500), selectedPos);

colorDialog.setOnColorSelectedListener(this);

colorDialog.setAdapter(new CircleColorAdapter(this));

colorDialog.setLayoutManager(new GridLayoutManager(MainActivity.this, GRID_COUNT));

colorDialog.show(getSupportFragmentManager(), CIRCLE_COLOR_PICKER_TAG);

  
}
 catch (IllegalAccessException iae) {

Log.e(MainActivity.class.getSimpleName(), iae.getMessage(), iae);

  
}

Note that depending on orientation or screen size, you may want to consider how many columns you add to the GridLayoutManager. For example, 5 columns on a Nexus 6P begin to overlap and don't look god together.

Sample

To see the library in action, this is the output of getting all 500 level colors and displaying them in individual TextViews:

Here is an example of the ColorPicker in action:

Colors

Here's the list of the colors names. Change "X" to the color level, like "50" or "A100".

  • mds_red_X
  • mds_pink_X
  • mds_purple_X
  • mds_deeppurple_X
  • mds_indigo_X
  • mds_blue_X
  • mds_lightblue_X
  • mds_cyan_X
  • mds_teal_X
  • mds_green_X
  • mds_lightgreen_X
  • mds_lime_X
  • mds_yellow_X
  • mds_amber_X
  • mds_orange_X
  • mds_deeporange_X
  • mds_brown_X
  • mds_grey_X
  • mds_bluegrey_X

The color levels can be:

  • 50
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900

And the accent ones are:

  • A100
  • A200
  • A400
  • A700

Example of a color: mds_orange_A400.

Reminder: brown, grey, and bluegrey don't have accent colors.

We highly recommend you use this library for the mds_white and mds_black colors as well, as some OEM's change the @android:color/white resource - https://twitter.com/mandybess/status/910555678476951552

The full color palettes as well as some more information on how to use them can be found in Google's Material Design Specifications.

Elevation values

To know which elevation value to use, please refer to the material design specs.

And with that you're all set. Go make some awesome apps with our lib :)

Credits & Contact

Material Design Specs Lib was created with <3 by:

With special thanks to Eric Cugota for helping us get this into Bintray and make it available for you.

And it's released under Android Essence blog.

License

Material Design Specs Lib is available under the MIT License.

When you use it, don't forget to mention us ;)

Happy coding!

Resources

Add support for emoticons and GIF easily. EmoticonGIFKeyboard is an easy to integrate, customizable and lightweight library to add support for emojis and GIFs.

The easy way to take screenshots of your application programmatically.

Newtron Watchdog allows the critical applications you develop for Android to keep running even after an application crash.

Love Architecture Components' ViewModels but hate how hard it is to instantiate them?

Hire Alfred and start doing just this!

This project allowing you to create circular and rounded corner imageview in android through simplest way.

It uses a BitmapShader and does not:

  • create a copy of the original bitmap
  • use a clipPath (which is neither hardware accelerated nor anti-aliased)
  • use setXfermode to clip the bitmap (which means drawing twice to the canvas)

This little Project written by Kotlin used Retrofit and Rxjava and so on. Pull data from Readhub which is a news aggregator website in China.

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