Reprint Please specify source: http://blog.csdn.net/bbld_/article/details/40584331
Here are a few drawables features to help you implement material design in your app:
L can draw coloring
L Highlight the color extraction
L Vector-able-to-paint
This section shows you how to use these features in your app.
Hue drawable Resources
If you use the system version above Android5.0 (API level 21), you can colorize bitmaps and 9patch graphs as transparency masks. You can use color resources or color resources in theme properties (for example,? android:attr/colorprimary) to colorize them. Typically, you can create these resources one at a time and automatically paint them to match your theme.
You can use the settint () method to colorize a bitmap resource or a 9patch resource object. You can also set the color and pattern of shading in your layouts using the android:tint property and the Android:tintmode property.
Extract the highlighted color from the image
The support library for Android R21 or above contains the Palette class, which allows you to extract prominent colors from the image. This class can extract the following prominent colors:
L Vibrant (full of vitality)
L Vibrant Dark (vibrant black)
L Vibrant light (vibrant bright)
L Muted (soft)
L muted Dark (soft black)
L Muted lighr (soft light)
To extract these colors, pass a bitmap object to the palette.generate () static method in the background thread where you loaded the picture. If you do not apply a thread, call the Palette.generateasync () method and provide a listener to replace it.
You can use getter methods in the Palette class to retrieve prominent colors, such as Palette.getvibrantcolor.
To use the Palette class in your project, add the following gradle that are dependent on your program's module:
dependencies { ... Compile ' com.android.support:palette-v7:21.0.+ '}
add: Use the Palette class in eclipse:
It's easy to copy the Palette support jar package from the V7 Support library in the SDK to the Libs folder in your project extras.
For more information, see the API documentation for the palette class .
Creating vectors (vector) drawables
In Android 5.0 (API level 21) or above, you can define vector drawables, which can be scaled without losing clarity. You just need a resource file for a vector picture, and you need to set a resource file for each screen density. To create a vector picture, you need to define the details of the shape elements in the <vector>xml file.
The following example defines a heart-shaped vector Image:
<!--res/drawable/heart.xml--><vector xmlns:android= "Http://schemas.android.com/apk/res/android" <!--intrinsic size of the drawable- android:height= "256DP" android:width= "256DP" <!--size of The virtual canvas-- android:viewportwidth= " android:viewportheight=" > <!--draw a path -- <path android:fillcolor= "#8fff" 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>
Vector images are represented as vectordrawable objects in Android. For more information about the pathdata syntax, see the documentation reference for SVG Path . For more information about animation vector drawable Properties, see animatingvector drawables ( not updated ).
Demo Presentation effect:
Demo Source: http://download.csdn.net/detail/bbld_/8094905
Android Material design-working with Drawables (using drawable)-(v)