zoukankan      html  css  js  c++  java
  • Android Material Design-Working with Drawables(使用Drawable)-(五)

    转载请注明出处:http://blog.csdn.net/bbld_/article/details/40584331

    翻译自:http://developer.android.com/training/material/drawables.html 


    以下的几点drawables 的功能帮助你在你的app中实现material design:

    l  可绘制着色

    l  突出的颜色提取

    l  矢量可绘性

    本章节向你展示了怎么在你的app中使用这些功能。

    色调Drawable资源

    假设使用Android5.0(API级别21)以上的系统版本号,你能够着色位图和9patch图作为透明度蒙板。你能够使用颜色资源或者主题属性中的颜色资源(比如,?android:attr/colorPrimary)给它们着色。通常。你仅仅需一次就可以创建这些资源,并自己主动将它们上色以匹配你的主题。

    你能够使用setTint()方法给位图资源或者9patch资源对象着色。你还能够在你的布局中使用android:tint属性和android:tintMode属性设置着色的颜色和模式。

    从图像中提取突出的颜色

    Android r21或以上的支持库中包括了Palette类,它能让你从图像中提取突出的颜色。这个类能提取下面突出的颜色:

    l  Vibrant(充满活力的)

    l  Vibrant dark(充满活力的黑)

    l  Vibrant light(充满活力的亮)

    l  Muted(柔和的)

    l  Muted dark(柔和的黑)

    l  Muted lighr(柔和的亮)

    要提取这些颜色,在你载入图片的后台线程中传递一个位图对象给Palette.generate()静态方法。假设你不适用线程,则调用Palette.generateAsync()方法而且提供一个监听器去替代。

    你能够在Palette类中使用getter方法来从检索突出的颜色,比方Palette.getVibrantColor

    要在你的项目中使用Palette类,添加以下的Gradle依赖到你的程序的模块(module)中:

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

    补充:在Eclipse中使用Palette类:

    非常easy,把sdk里的extras里的v7支持库里的palette支持jar包拷贝到你项目的libs目录就可以。



    很多其它的信息。请參阅Palette类的API文档说明


    创建矢量(vector)Drawables

    在Android 5.0(API级别21)或以上的系统中。则能够定义矢量drawables。它能够在不失清晰度的情况下进行缩放。你只须要须要一个矢量图片的资源文件,而须要为每一个屏幕密度设置一个资源文件。要创建一个矢量图片,你须要定义形状元素的细节在<vector>XML文件里。

    以下的样例定义了一个心形的矢量图像:

    <!-- 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="32"
        android:viewportHeight="32">
    
      <!-- 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>
    

    矢量图像在Android中被表示为VectorDrawable对象。

    很多其它有关pathData语法的信息,请參阅SVG Path 的文档參考。很多其它有关动画矢量drawable属性,请參阅AnimatingVector Drawables(Defining Custom Animations(自己定义动画))


    Demo演示效果:


    demo源代码下载地址:http://download.csdn.net/detail/bbld_/8094905



  • 相关阅读:
    vc++ 编译器工具
    lesson 17 进程间通信 孙鑫 VC++
    VC++ msdn
    VC++ 相关问题
    MySQL
    Git
    Angular
    Linux
    阿里云服务器
    Git
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5384117.html
Copyright © 2011-2022 走看看