博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Material Design系列第五篇——Working with Drawables
阅读量:6969 次
发布时间:2019-06-27

本文共 2460 字,大约阅读时间需要 8 分钟。

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 or 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 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 object to the static method in the background thread where you load your images. If you can't use that thread, call the 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 class in your project, add the following to your app's module:

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

For more information, see the API reference for the 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:

    android:height="256dp"     android:width="256dp"    
    android:viewportWidth="32"     android:viewportHeight="32">  
 

Vector images are represented in Android as objects. For more information about the pathData syntax, see the . For more information about animating the properties of vector drawables, see .

转载地址:http://mcisl.baihongyu.com/

你可能感兴趣的文章
web性能优化——使用RAIL模型评估性能
查看>>
微信JS-SDK分享
查看>>
python 最快 web 框架 Sanci 快速入门
查看>>
ES2015入门系列1-初识ES2015
查看>>
Python: 链式赋值的坑
查看>>
Node.js开发中的Cookie和Session
查看>>
【收藏】8段JQuery处理表单的代码片段,很实用
查看>>
利用 Css 制作精美的卡片UI
查看>>
Jmeter使用陷阱
查看>>
夏日葵电商:微信商城系统开发,分享产品运营几大细节
查看>>
ios证书--快速创建iOS证书及描述文件工具
查看>>
web前端开发前的环境搭建
查看>>
jQuery源码分析之noConflict()
查看>>
7步学会在Windows下上架iOS APP流程
查看>>
PHP使用CURL详解
查看>>
nodejs源码中的require问题
查看>>
带标签的长标题省略展示的实现
查看>>
区块链技术精华:四十种智能合约支持平台(四)
查看>>
DevOps是90%的改变和10%的技术
查看>>
Yelp研发实践:使用服务拆分单块应用
查看>>