Create material Design-style Android apps-using drawable

Source: Internet
Author: User

The following drawables features help you implement material Design in your application:

Picture Resource Coloring

In Android 5.0 (API 21) and later versions, Bitmap and. 9 png can be shaded by defining transparency masking. You can coloring by using color resources or the properties of the theme to parse the color resources (for example, ?android:attr/colorPrimary ). Usually we create it once and then the resource adapts to the theme.

You can use methods for coloring bitmapdrawable or ninepatchdrawable objects setTint() . You can use the and properties in the layout file to android:tint android:tintMode set the shading color and shading modes.

Extract the highlight color from the picture

The support library R21 and higher versions include Palette classes that extract the highlight colors from a single image. This class can lift several prominent colors:

Vibrant full of vitality

Vibrant dark dark and full of vitality

Vibrant light bright full of vitality

Muted soft

Muted dark Dark soft

Muted light bright soft

Pass a bitmap object to the static method Palette.generate (), which will help you extract colors from the background thread in a background thread. If you cannot use this background thread, use the Palette.generateasync () method and set a listener listener.

You can get the highlight color from the picture using the Getter method in the palette class, such as Palette.getvibrantcolor.

To use the Palette method in your project, you need to include the jar for the V7 package palette in your project, and Gradle Dependecy is added in the following way:

... compile ' com.android.support:palette-v7:21.0.+ '

Here is the sample code:

Palette.generateasync (Bitmap, new Palette.paletteasynclistener () {public     void ongenerated (Palette Palette) {         //do something with colors         ... Palette.getvibrantcolor (Color.Black); Get a color in RGB value     }});

For more information, please see the API documentation for Paltette: http://developer.android.com/reference/android/support/v7/graphics/Palette.html

Create Vector drawables

In Android 5.0 and later versions, you can create vector drawable that don't distort when zoomed in. You only need to define a vector picture file, instead, you need to create multiple files for different resolutions using the bitmap bitmap. To create a vector picture, you need to explain the details of the graph under the tags of the XML file.

Here is an example:

<?xml version= "1.0" encoding= "Utf-8"?><!--res/drawable/heart.xml--><vector xmlns:android=    " Http://schemas.android.com/apk/res/android "    android:width=" 256DP "    android:height=" 256DP "    android: viewportheight= "Android:viewportwidth="    >    <!--draw a path-to-    <path        android: Fillcolor= "#f15467"        android:pathdata= "m20.5,9.5                        c-1.955,0,-3.83,1.268,-4.5,3                        c-0.67,-1.732,-2.547 , -3,-4.5,-3                        c8.957,9.5,7,11.432,7,14                        c0,3.53,3.793,6.257,9,11.5                        c5.207,-5.242,9,-7.97,9,-11.5                        c25,11.432,23.043,9.5,20.5,9.5z "/></vector>

The diagram above shows the following:

Vector pictures are displayed on Android as VectorDrawable objects. For more information, see SVG Path Reference.

Reference: http://developer.android.com/training/material/drawables.html

Original address: http://blog.isming.me/2014/11/03/creating-app-with-material-design-four-drawables/, reproduced please indicate the source.

Create material Design-style Android apps-using drawable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.