Material Design系列第五篇——Working with Drawables
Working with Drawables
This lesson teaches you to
You should also read
The following capabilities for drawables help you implement material design in your apps:
- Drawable tinting
- Prominent color extraction
- Vector drawables
This lesson shows you how to use these features in your app.
Tint Drawable Resources
With Android 5.0 (API level 21) and above, you can tint bitmaps and nine-patches defined as alpha masks. You can tint them with color resources or theme attributes that resolve to color resources (for example, ?android:attr/colorPrimary
). Usually, you create these assets only once and color them automatically to match your theme.
You can apply a tint to BitmapDrawable
or NinePatchDrawable
objects with the setTint()
method. You can also set the tint color and mode in your layouts with the android:tint
and android:tintMode
attributes.
Extract Prominent Colors from an Image
The Android Support Library r21 and above includes the Palette
class, which lets you extract prominent colors from an image. This class extracts the following prominent colors:
- Vibrant
- Vibrant dark
- Vibrant light
- Muted
- Muted dark
- Muted light
To extract these colors, pass a Bitmap
object to the Palette.generate()
static method in the background thread where you load your images. If you can't use that thread, call the Palette.generateAsync()
method and provide a listener instead.
You can retrieve the prominent colors from the image using the getter methods in the Palette
class, such as Palette.getVibrantColor
.
To use the Palette
class in your project, add the following Gradle dependency to your app's module:
- dependencies {
...
compile 'com.android.support:palette-v7:21.0.+'
}
For more information, see the API reference for the Palette
class.
Create Vector Drawables
Video
Android Vector Graphics
In Android 5.0 (API Level 21) and above, you can define vector drawables, which scale without losing definition. You need only one asset file for a vector image, as opposed to an asset file for each screen density in the case of bitmap images. To create a vector image, you define the details of the shape inside a <vector>
XML element.
The following example defines a vector image with the shape of a 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="32"
android:viewportHeight="32">- <!-- draw a path -->
<pathandroid: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 in Android as VectorDrawable
objects. For more information about the pathData
syntax, see the SVG Path reference. For more information about animating the properties of vector drawables, see Animating Vector Drawables.
Material Design系列第五篇——Working with Drawables的更多相关文章
- Material Design系列第七篇——Maintaining Compatibility
Maintaining Compatibility This lesson teaches you to Define Alternative Styles Provide Alternative L ...
- Material Design系列第六篇——Defining Custom Animations
Defining Custom Animations //自定义动画 This lesson teaches you to //本节课知识点 Customize Touch Feedback //1. ...
- Material Design系列第四篇——Defining Shadows and Clipping Views
Defining Shadows and Clipping Views This lesson teaches you to Assign Elevation to Your Views Custom ...
- Material Design系列第三篇——Using the Material Theme
Using the Material Theme This lesson teaches you to Customize the Color Palette Customize the Status ...
- Material Design系列第八篇——Creating Lists and Cards
Creating Lists and Cards //创建列表和卡片 To create complex lists and cards with material design styles in ...
- Android Material Design系列之主题样式介绍说明
今天这篇文章应该算是Material Design系列的补充篇,因为这篇文章本来应该放到前面讲的,因为讲的是主题嘛,对于一些状态和颜色的介绍,因为我们一新建一个项目时,系统自带了三个属性的颜色,现在就 ...
- 前端工程师技能之photoshop巧用系列第五篇——雪碧图
× 目录 [1]定义 [2]应用场景 [3]合并[4]实现[5]维护 前面的话 前面已经介绍过,描述性图片最终要合并为雪碧图.本文是photoshop巧用系列第五篇——雪碧图 定义 css雪碧图(sp ...
- Material Design系列第二篇——Getting Started
Getting Started This lesson teaches you to Apply the Material Theme Design Your Layouts Specify Elev ...
- Material Design系列第一篇——Creating Apps with Material Design
Creating Apps with Material Design //创建Material Design的App Material design is a comprehensive guide ...
随机推荐
- lua----------------使用VS2015搭建lua开发环境的一些侥幸成功经验,
所以本篇博文介绍在Windows平台下,使用VS2015搭建lua开发环境的一些侥幸成功经验,安装过程参考网上教程,安装过程如下(参考http://www.byjth.com/lua/33.html) ...
- Unity---------Mesh理解
Mesh顾名思义“网格”,Unity3D里面所有的模型都是由Mesh组成的,UI也不例外. 例如下图,模型上的一个个小网格就是Mesh,这些Mesh有不同的三维顶点(Vector3),共同组成了一个3 ...
- (转)android系统架构及源码目录结构
转自:http://blog.csdn.net/finewind/article/details/46324507 1. Android系统架构: android系统架构采用了分层架构的思想,如下图所 ...
- (转)PCM数据格式
1. 音频简介 经常见到这样的描述: 44100HZ 16bit stereo 或者 22050HZ 8bit mono 等等. 44100HZ 16bit stereo: 每秒钟有 4410 ...
- nodejs基础 -- 全局对象
全局对象:javascript中的一个特殊对象 全局变量:该特殊对象及其所有属性 该对象为:在浏览器javascript中,为window:在nodejs中,为global(所有全局变量都是globa ...
- [原创]Allegro 导入DXF文件,保留布好的线路信息
最近智能钥匙产品开发过程中,由于结构装配尺寸的偏差,需要对电路PCB外框OUTLINE进行缩小调整,并且USB插座定位孔改变. Allegro软件在线性绘制方面是有严重缺陷的,想绘制一个异形的板框比较 ...
- zookeeper ACL使用
生产环境中,经常会有多个项目使用zookeeper,例如多个hbase集群.每个项目搭建一套独立的zookeeper,无论从机器成本,还是运维成本,都是一笔额外的开销. 然而多项目,多集群共用zook ...
- mothur 计算稀释性曲线
在微生物分析中,经常使用稀释性曲线来评估测序量是否足够:可以使用mothur 这个软件来完成 rarefaction.single 命令用来做稀释性曲线,既可以对单个样本单独分析,也可以一次对多个样本 ...
- php + crontab 执行定时任务
1.yii2中的console <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 2008 Yi ...
- Java编程思想学习笔记——初始化与清理(二)
成员初始化 Java尽力保证:所有变量在使用前都能得到适当的初始化. 方法的局部变量:未初始化,编译错误. void f(){ int i; // System.out.println(i);//编译 ...