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 ...
随机推荐
- htop和ncdu
今天突然发现服务器不能够mkdir了,说没空间,用df -h命令显示空间是很大的,网管过来用ncdu命令一下显示某些文件夹中有好多文件,说是因为linux中小文件太多引发,即实际空间还有很多,但是小文 ...
- Spring Boot 8080端口被占用抛出异常
问题: SpringBoot------8080端口被占用抛出异常 解决: 进到项目下这两个文件,添加“server.port=8888”即可
- (原)关于sdl在部分机器上做视频显示,改变显示窗口大小会崩溃
今天测试人员反应,之前做的视频绘图显示,会在她机器上,会出现崩溃现象,最后我在她机器上对代码进行跟踪,发现在某种情况,确实会崩溃. 最主要的原因是,视频显示窗口变成非活动窗口的时候,sdl内部会循环消 ...
- js 操作json对象增删改
//将表单序列化成字符串 $.fn.serializeObject = function () { var obj = {}; var count = 0; $.each(this.serialize ...
- C# 窗口自适应窗口宽度和高度
其实winform并不适合做自适应这玩意的,虽然,能做是能做, 就像菜刀一样能切水果,但是,不是那么合适,毕竟有水果刀 wpf做自适应拉伸窗体,会更好一些. 代码: #region 自适应 priva ...
- Sublime Text 3技巧:支持GB2312和GBK编码
From: http://blog.csdn.net/ubuntulover/article/details/21101979 Sublime Text 3与Sublime Text 2的不同 其实有 ...
- iOS:第三方库使用非ARC编译
iOS: 解决某些第三方库因为ARC不能使用的问题 1.在target下面的build phases下有一个compile source,下面有很多待编译文件.可以看到一个compile flag,可 ...
- 中企ITIL需软落地
IT技术的发展对现代企业产生了深远的影响.企业信息化建设越深入,信息系统的规模越大,业务对IT系统的依赖性也越大,由此对IT服务的要求越高,如何 对繁多的IT技术进行有效的管理,最大程度地利用企业现有 ...
- PHP对HTML代码尸体编码2个函数
1.htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体. 2.htmlentities() 函数把字符转换为 HTML 实体. 记录下
- golang 内存分析/动态追踪
如果你的go程序是用http包启动的web服务器,你想查看自己的web服务器的状态.这个时候就可以选择net/http/pprof.你只需要引入包_"net/http/pprof" ...