Creating Apps with Material design--working with Drawables

Source: Internet
Author: User

reprint Please specify Http://blog.csdn.net/eclipsexys translation from developer Android, time haste, there are translation questions please note that, thank you


Drawable

By drawing the following features to help you implement material design for your application:


can draw coloring
Prominent color extraction
Vector can be plotted

This lesson will show you how to use these features of your application.


drawable resources that can be graded
With Android5.0 (API level 21) above, it is possible to define shading as transparent matte bitmaps and nine-patches graphs. You can adjust their color resources or theme properties to help resolve color resources (for example, ?android:attr/colorPrimary)。 Typically, you will create these assets only once and automatically paint them to match your theme.

You can use color to bitmapdrawable or ninepatchdrawable objects with the Settint () method. You can also set the color and mode of the hue in different interfaces with android:tintAnd android:tintModeproperty to extract the color highlighting from the image.

The Android Support Library R21 and above includes panel classes, which allow you to extract prominent colors from the image. The following prominent colors are extracted from this class:

Full of vitality
A vibrant darkness
A vibrant light
Mute
Soft and dark
Soft light.

To extract these colors, pass a bitmap object to the Palette.generate () static method that you loaded the picture in the background thread. If you cannot call the Palette.generateasync () method using a thread, and provide a listener instead.

Can you use getter methods from images?? The color is highlighted in the Panel class, such as Palette.getvibrantcolor.

To use a Palette class project, the following cradle relies on the modules added to your application:

dependencies {    ...    Compile ' com.android.support:palette-v7:+ '}

Create Verctordrawable

With Android 5.0 (API level 21), you can define vector-capable objects, where the scale is not yet clear. Your vector image requires only one resource file, not a bitmap image in the case of an asset file, per screen density. To create a vector image, you define the details of a shape inside a <vector> XML element.

The following example defines the shape vector image of the heart:

<!--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 Path reference for SVG. For more information about animating the properties of a vector-drawn object, see vector animation effects draw an object.








Creating Apps with Material design--working with Drawables

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.