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
Android Material Design-Working with Drawables(使用Drawable)-(五)的更多相关文章
- Android Material Design 兼容库的使用
Android Material Design 兼容库的使用 mecury 前言:近来学习了Android Material Design 兼容库,为了把这个弄懂,才有了这篇博客,这里先推荐两篇博客: ...
- Android Material Design Ripple Effect在Android5.0(SDK=21)以下Android版本崩溃问题解决
Android Material Design Ripple Effect在Android5.0(SDK=21)以下Android版本崩溃问题解决 附录1的Android Ripple Effect水 ...
- Android Material Design : Ripple Effect水波波纹荡漾的视觉交互设计
Android Material Design : Ripple Effect水波波纹荡漾的视觉交互设计 Android Ripple Effect波纹荡漾效果,是Android Materia ...
- Android Material Design的FloatingActionButton,Snackbar和CoordinatorLayout
如果是为了兼容低版本的Android系统,则需要引用Android Material Design的扩展支持库,我在之前的一篇文章张,较为详细的说明了如何导入Android Material Desi ...
- MaterialEditText——Android Material Design EditText控件
MaterialEditText是Android Material Design EditText控件.可以定制浮动标签.主要颜色.默认的错误颜色等. 随着 Material Design 的到来, ...
- Android Material Design控件学习(三)——使用TextInputLayout实现酷市场登录效果
前言 前两次,我们学习了 Android Material Design控件学习(一)--TabLayout的用法 Android Material Design控件学习(二)--Navigation ...
- Android Material Design简单使用
吐槽 作为一个 Android developer,没有什么比拿着 UI 设计的一堆 iOS 风格的设计 来做需求更恶心的了,基本所有空间都要照着 iOS 来画一遍,Material Design 辣 ...
- Android Material Design NavigationView 及 Palette 颜色提取器
DrawerLayout + NavigationView DrawerLayout布局,通常在里面添加两个子控件,程序主界面添加到NavitagionView前面. <android.supp ...
- Android material design support library -- CollapsingToolbarLayout简介
本文是codetrick上material design support library教程的第三篇,主要讲的是CollapsingToolbarLayout的概念和应用方法. 原文链接:Materi ...
随机推荐
- 如何在Linux启动的时候执行一个命令
在Linux启动起来时,执行一个命令的设置方法== 例如:需要执行的命令是cvslockd ============第一种方式:根据运行级别配置======================== 第一步 ...
- MySQL 作业题及答案
MySQL 测试题 一. 表关系: 请创建如下表,并创建相关约束 创建表sql如下: /* Navicat MySQL Data Transfer Source Server : 192.168.11 ...
- leetcode 之Remove Duplicates from Sorted Array(2)
描述 Follow up for ”Remove Duplicates”: What if duplicates are allowed at most twice? For exampl ...
- PostGreSQL数据库安装配置说明
windows 10 x64 pro 1703安装postgresql-9.6.3-2-windows-x64.exe数据库,步骤如下: 第一:下载数据库安装程序,下载地址为:https://www. ...
- radis相关操作
redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...
- 邀请用户进TestFlight 体验 App 的测试版本
iphone手机用户,在工作中常见到,APP版本现在是Beta阶段(iOS版本),需要邀请一些用户来体验新版本,在版本上线前提出更好的建议及时进行修改,此时用到了testflight,很方便的通过邀请 ...
- 关于HTML5 boilerplate 的一些笔记
最近在研究HTML5 boilerplate的模版,以此为线索可以有条理地学习一些前端的best practice,好过在W3C的文档汪洋里大海捞针……啊哈哈哈…… 开头的IE探测与no-js类是什么 ...
- Model Binder
上面需检测id是否为null 如果未提供id值或id值类型不匹配,则使用默认值.但仍需校验值是否超出范围
- linq to sql: 在Entityfamework Core中使用多个DbContext
最近在学习DotNetCore并做一个自己的小项目,分为了多个数据库,AccountDbContext和BlogDbContext, 发blog的时候需要用到Account的信息,但是再Blog中只记 ...
- 【C#日期系列(一)】--C#获取某月第一天0分0秒以及最后一天59分59秒
工作中可能会遇到很多不常见的需求,比如这次需要获取某个月的第一天和最后一天 #region 取得某月的第一天0分0秒 /// <summary> /// 取得某月的第一天0分0秒 /// ...