Website address: Https://developer.android.com/intl/zh-tw/training/material/drawables.html#DrawableTint
The feature of tablets can help you implement material design in your app:
• Picture Coloring
• Color Extraction
• Vector images
Tint drawable Resources for picture resource coloring at Android 5.0 (API level 21) and above, you can define images and 9-patch as masking transparency. You can use color resources (such as,? android:attr/colorprimary) or theme properties to paint them. Typically, you only need to create these resources once, and automatically match your theme to color them.
The bitmapdrawable and Ninepatchdrawable objects can be dyed using settint (int tint). You can also define the Android:tint and Android:tintmode properties in XML.
• For parameters of settint (int tint), it can be a property under a @color/, or the item in an XML Selector,selector is used numerically, such as:
<selector xmlns:android="Http://schemas.android.com/apk/res/android"> <item android:state_focused="true" Android:color="@color/testcolor1"/> <item android:state_pressed="true" android:state_enabled="false" Android:color="@color/testcolor2" /> <item android:state_enabled="false" Android:color="@color/testcolor3" /> <item Android:color="@color/testcolor5"/> </selector>
• About defining attributes in XML, such as:
<? XML Version="1.0"encoding="utf-8"?>
< Nine-patch xmlns:android="Http://schemas.android.com/apk/res/android"
android:tint="@color/abc_primary_text_material_light"
Android:tintmode="Src_over"
... >
</nine-patch>
Extract prominent Colors from an Image Extract the obvious color from the picture there is a android-support-v7-palette.jar in the SUPPORT-V7 library on the API21, which allows you to extract some conspicuous colors from the image:
Palette p = palette.generate (Bitmap Bitmap);
• Bright P.getvibrantcolor (int defaultcolor); Bright Dark P.getdarkvibrantcolor (int defaultcolor); Vivid bright P.getlightvibrantcolor (int defaultcolor); Soft P.getmutedcolor (int defaultcolor); Soft dark P.getdarkmutedcolor (int defaultcolor); Soft bright P.getlightmutedcolor (int defaultcolor);palette.generate (), used in a background thread, can use Palette.generateasync () if the Palette object is created in the foreground thread .
Create vector drawables creates vectors in Android 5.0 (API level 21) and above can create vector pictures, as in the following example can draw a heart-shaped vector diagram:
<!--res/drawable/heart.xml --<vector xmlns:android= "Http://schemas.android.com/apk/res/android"<!--intrinsic size of 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 C 5.207,-5.242,9,-7.97,9,-11.5 c25,11.432,23.043,9.5,20.5,9.5z " /></vector>
Vector images use the Vectordrawble object in Android to correspond to it. For more information on path, see: Http://www.w3.org/TR/SVG11/paths.html#PathData.
Android (lollipop/5.0) Material Design (v) Use picture