Palette的使用
来源:互联网 发布:国产windows平板推荐 编辑:程序博客网 时间:2024/06/08 19:09
(转载,请注明出处:http://www.kennethyo.me/post/android/palettechu-ji-shi-yong)
相信有不少的人已经开始关注Android Lollipop,全新的Material设计风格让人眼前一亮,Material强调大胆的阴影和高亮搭配,引用那些意料之外和充满活力的颜色。
这里就要说到,不久前Android在v7包中更新的Palette。Palette可以让我们构造色彩鲜艳的界面更加方便,通过一个图片的bitmap
来获取图片当中明暗对比的颜色。
初始化Palette
Palette
通过一个静态方法进行初始化,并且需要传入一个bitmap
,这个bitmap
是我们要获取颜色图片的位图。
Palette palette = Palette.generate(bitmap);
还有一个异步方法:
//提供了一个异步方法Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { }});
获取Palette.Swatch
通过以下几种方法获取相应的Palette.Swatch
,Palette.Swatch
是包含我们获取到颜色的一个载体
palette.getVibrantSwatch();palette.getMutedSwatch();palette.getLightVibrantSwatch();palette.getLightMutedSwatch();palette.getDarkVibrantSwatch();palette.getDarkMutedSwatch();
通过Palette.Swatch
获取到颜色
针对Android,Palette.Swatch.getRgb()
返回一个int
RGB颜色值。例如如下的用法:
TextView tv1 = (TextView) findViewById(R.id.tv1);//返回一个活力的颜色tv1.setTextColor(palette.getVibrantSwatch().getRgb());//返回一个柔和的颜色tv1.setBackgroundColor(palette.getMutedSwatch().getRgb());TextView tv2 = (TextView) findViewById(R.id.tv2);//返回一个活力的亮色tv2.setTextColor(palette.getLightVibrantSwatch().getRgb());//返回一个柔和的亮色tv2.setBackgroundColor(palette.getLightMutedSwatch().getRgb());TextView tv3 = (TextView) findViewById(R.id.tv3);//返回一个活力的暗色tv3.setTextColor(palette.getDarkVibrantSwatch().getRgb());//返回一个柔和的暗色tv3.setBackgroundColor(palette.getDarkMutedSwatch().getRgb());TextView tv4 = (TextView) findViewById(R.id.tv4);//返回一个适合做标题的颜色tv4.setTextColor(palette.getVibrantSwatch().getTitleTextColor());//返回一个适合做主题的颜色tv4.setBackgroundColor(palette.getDarkMutedSwatch().getBodyTextColor());
总体上看,Palette的使用简单,没有复杂的方法,更方便我们针对material风格进行开发。
demo地址
2 0
- Palette的使用
- Palette的使用
- Palette的简单使用
- Palette调色板的使用
- Palette的使用
- Palette的简单使用
- 【UI】Palette的使用API
- Android Palette 调色板 的使用
- 安卓Palette(颜色拾取)的使用
- Android 5.0 Palette的使用小结
- Android RecyclerView、CardView、Palette的使用
- 使用Palette提取图片的颜色信息
- Android 5.X Color Palette的使用
- palette调色板初级使用
- android Palette使用详解
- Android Palette使用详解
- Android L中的RecyclerView 、CardView 、Palette的使用
- Android L中的RecyclerView 、CardView 、Palette的使用
- 云计算设计模式(三)——补偿交易模式
- 系统相机的调用(只能真机试验)
- [转]Java AIO学习
- 黑马程序员---基础学习----面向对象1
- Linux集群之概念篇
- Palette的使用
- HashMap HashTable HashSet区别剖析
- Shell Sort with array[]
- C++,string实现
- android4.4中jni的native的方法无法找到的解决方案
- Cytoscape绘图初探
- openstack学习笔记一 虚拟机启动过程代码跟踪
- leetcode Letter Combinations of a Phone Number
- 自己写EnumHelper