安卓5.0新特性之Palette
根据图片来决定标题的颜色和标题栏的背景色,这样视觉上更具有冲击力和新鲜感,而不像统一色调那样呆板。
Palette这个类能提取以下突出的颜色:
Vibrant(充满活力的)
Vibrant dark(充满活力的黑)
Vibrant light(充满活力的亮)
Muted(柔和的)
Muted dark(柔和的黑)
Muted lighr(柔和的亮)
使用方法:传递Bitmap对象给Palette.generate()静态方法。如果不适用线程,则调用Palette.generateAsync()方法并且提供一个监听器去替代。
Palette类中使用getter方法来从检索突出的颜色,比如 Palette.getVibrantColor
接下来是步骤:
在安卓过程中导入V7包
如下代码:
mTextView = (TextView)findViewById(R.id.textView1);
Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.test);
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch vibrant = palette.getVibrantSwatch();
if(vibrant != null){
mTextView.setBackgroundColor(vibrant.getRgb());
mTextView.setTextColor(vibrant.getTitleTextColor());
}
}
});
}
我是在布局中添加了背景图片 test.jpg 如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/test"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="根据背景图片改变文字颜色" />
</RelativeLayout>
安卓5.0新特性之Palette的更多相关文章
- Kotlin实例----android5.0新特性之palette
一.Palette的使用 使用Palette可以让我们从一张图片中拾取颜色,将拾取到的颜色赋予ActionBar,StatusBar以及UI背景色可以让界面色调实现统一或者加载不同图片时同步变化色调 ...
- 安卓6.0新特性在Fragment申请运行时权限
今天在Fragment申请权限时代码如下: public void getContacts(){ int flag = ActivityCompat.checkSelfPermission(getAc ...
- android6.0、7.0、8.0新特性总结之开发应用时加以考虑的一些主要变更。
android6.0 参考一:简书Android 6.0 新特性详解 参考二:关于Android6.0以上系统的权限问题 参考三:值得你关注的Android6.0上的重要变化(一) 参考四:值得你关注 ...
- 浅谈Tuple之C#4.0新特性那些事儿你还记得多少?
来源:微信公众号CodeL 今天给大家分享的内容基于前几天收到的一条留言信息,留言内容是这样的: 看了这位网友的留言相信有不少刚接触开发的童鞋们也会有同样的困惑,除了用新建类作为桥梁之外还有什么好的办 ...
- Java基础和JDK5.0新特性
Java基础 JDK5.0新特性 PS: JDK:Java Development KitsJRE: Java Runtime EvironmentJRE = JVM + ClassLibary JV ...
- Visual Studio 2015速递(1)——C#6.0新特性怎么用
系列文章 Visual Studio 2015速递(1)——C#6.0新特性怎么用 Visual Studio 2015速递(2)——提升效率和质量(VS2015核心竞争力) Visual Studi ...
- atitit.Servlet2.5 Servlet 3.0 新特性 jsp2.0 jsp2.1 jsp2.2新特性
atitit.Servlet2.5 Servlet 3.0 新特性 jsp2.0 jsp2.1 jsp2.2新特性 1.1. Servlet和JSP规范版本对应关系:1 1.2. Servlet2 ...
- 背水一战 Windows 10 (1) - C# 6.0 新特性
[源码下载] 背水一战 Windows 10 (1) - C# 6.0 新特性 作者:webabcd 介绍背水一战 Windows 10 之 C# 6.0 新特性 介绍 C# 6.0 的新特性 示例1 ...
- C# 7.0 新特性2: 本地方法
本文参考Roslyn项目中的Issue:#259. 1. C# 7.0 新特性1: 基于Tuple的“多”返回值方法 2. C# 7.0 新特性2: 本地方法 3. C# 7.0 新特性3: 模式匹配 ...
随机推荐
- change legend layout from 'vertical' to 'horizontal' in Paraview
********** # get color legend/bar for 'vLUT' in view 'renderView1'vLUTColorBar = GetScalarBar(vLUT, ...
- 2.js原型的基本概念
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- lua排序算法
SEED = ; --随机序列 可任取 NUM = ; --排序规模 --随机序列 初始数据 function GenRnd( seed, n ) --生成随机数 data = {}; local r ...
- PAT 1143 Lowest Common Ancestor
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...
- 处理回车提交、ctrl+enter和shift+enter都不提交->textarea正常换行
<input type="textarea" @on-keypress="handlerMultiEnter"> handlerMultiEnter ...
- 创建Maven版Java工程
步骤: 创建成功后,如图:
- UVa - 12451 - Let's call SPaDe a SPaDe
先上题目: Problem H: Let's call SPaDe a SPaDe Passing time, walking the passage, as you pass the String ...
- 玲珑杯 ACM Round #12
A =w= B 占坑 C 题意:有长度为n的序列A和长度为n的序列W,以及一个G,对于Ui,1<=Ui<=Wi,求Σgcd(Ai,Ui)=G的方案数,n<=1e3,Ai<=1e ...
- Codeforces Goodbye2016
A =w= B 0.0 C 题意:按顺序给出一个人一年参加cf比赛的信息,包括是div1还是div2,赛后rating的增减多少,求出这个人现在rating最多可能为多少 分析:模拟 设这个人刚开始分 ...
- -- > define的用法与学习(1)
在不久之前,我一直不理解为神马大家在做题时经常用define来代替某些函数,或者用来直接定义某些极大的变量.It is not until today that I understand why it ...