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 ...
随机推荐
- JDBC事务提交/回滚实例
以下是使用事务教程中描述的提交和回滚的代码示例. 此示例代码是基于前面章节中完成的环境和数据库设置编写的. 复制并将以下示例代码保存到:CommitAndRollback.java 中,编译并运行如下 ...
- (转)【多媒体封装格式详解】--- AAC ADTS格式分析
出自:http://blog.csdn.net/tx3344/article/details/7414543 http://www.it6655.com/2012/08/aac-adts-html ...
- ubuntu 14.04安装 DevStack的脚本配置文件——localrc
本文ubuntu 14.04安装 DevStack的脚本配置文件——localrc,本文件名已经逐渐被取代,但是出于后向兼容性,使用该文件仍然可以为stack.sh安装脚本指定安装DevStack时的 ...
- XAMPP permissions on Mac OS X
$ cd /Applications $ XAMPP/ 注意: 改变的是XAMPP目录,而不是htdocs ref: http://stackoverflow.com/questions/904697 ...
- win10专业版激活方法
slmgr.vbs /upk 此时弹出窗口显未“已成功卸载了产品密钥”. slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX 弹出窗口提示:“成功的安装了产品密钥”. s ...
- JAVA中的数字运算+号与字符串+号
(1)当“+”两边是非数值类型,“+”就被看作连接符. (2)当“+”两边都是数值类型,“+”就被看作算术运算中的加号. (3)当“+”一边是非数值,一边是数值类型,“+”就被看作连接符.
- jiffies存放
固然书本上讲明jiffies是jiffies_64的低32位,但是我还是自己测试了下,重点在于链接脚本的写法. 此处只是为了测试,因此简化链接脚本. /* link.lds */ 1 ENTRY(_s ...
- Android技巧分享——如何用电脑下载在Google play中应用的apk文件
[Android技巧分享系列] 1.Android技巧分享——让官方模拟器和genymotion虚拟机飞起来 2.Android技巧分享——如何用电脑下载在Google play中应用的apk文件 G ...
- vue如何加入百度联盟广告
在百度联盟代码位管理中创建好对应的代码位之后,点击获取代码,会看到这样一段js 直接复制粘贴到自己网页中便可显示对应广告. 在vue中由于都是vue组件,不支持直接在组件中加入这样一段一段的js代码, ...
- QT中C++与Html端通信例子
C++(服务端)和HTML(客户端)通过websocket通信,通过qwebchannel.js实现 C++ -> HTML,通过信号. HTML -> C++,直接调用函数. Main函 ...