android Palette调色板的使用方法
2016-03-29 14:38
330 查看
Material Design鼓励开发者使用动态颜色,尤其是当我们有丰富的图片资源要显示时,v7兼容包中的Palette库就是这样诞生的,它可以让我们从一张图片中抽取一部分颜色去控制我们的UI元素,从而创造一个沉浸式的体验,抽取的颜色会包括充满活力的和柔和的色调,这些色调会使前景文本颜色具有最佳的视觉效果.
如果是Eclipse首先我们找到sdk/extras/android/support/v7/palette/libs/android-support-v7-palette.jar导入我们的工程。
Palette 的属性
Palette.Swatch是一个提取颜色的样本,通过该类可以提取到包含了我们需要的颜色内容
•返回一个有活力的颜色. Palette.getVibrantSwatch()
•返回一个有活力的暗色. Palette.getDarkVibrantSwatch()
•返回一个有活力的亮色. Palette.getLightVibrantSwatch()
•返回一个柔和的颜色. Palette.getMutedSwatch()
•返回一个柔和的暗色. Palette.getDarkMutedSwatch()
•返回一个柔和的亮色. Palette.getLightMutedSwatch()
有活力的颜色和有活力的暗色是开发者使用最多的,具体使用哪一种取决于你自己
Swatch 属性
•getPopulation(): 返回被该样本代表的像素的总数
•getRgb(): 返回一个 RGB 颜色值
•getHsl(): 返回一个 HSL颜色值.
•getBodyTextColor(): 返回一个适合做内容体颜色的颜色值
•getTitleTextColor(): 返回一个适合做标题颜色的颜色值
如果是Eclipse首先我们找到sdk/extras/android/support/v7/palette/libs/android-support-v7-palette.jar导入我们的工程。
Bitmap map=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Palette.Builder palette = Palette.from(map); Palette.Swatch swatch = palette.generate().getVibrantSwatch(); TextView tv=(TextView)findViewById(R.id.title); if(swatch != null){ tv.setTextColor(swatch.getRgb()); }
Palette 的属性
Palette.Swatch是一个提取颜色的样本,通过该类可以提取到包含了我们需要的颜色内容
•返回一个有活力的颜色. Palette.getVibrantSwatch()
•返回一个有活力的暗色. Palette.getDarkVibrantSwatch()
•返回一个有活力的亮色. Palette.getLightVibrantSwatch()
•返回一个柔和的颜色. Palette.getMutedSwatch()
•返回一个柔和的暗色. Palette.getDarkMutedSwatch()
•返回一个柔和的亮色. Palette.getLightMutedSwatch()
有活力的颜色和有活力的暗色是开发者使用最多的,具体使用哪一种取决于你自己
Swatch 属性
•getPopulation(): 返回被该样本代表的像素的总数
•getRgb(): 返回一个 RGB 颜色值
•getHsl(): 返回一个 HSL颜色值.
•getBodyTextColor(): 返回一个适合做内容体颜色的颜色值
•getTitleTextColor(): 返回一个适合做标题颜色的颜色值
相关文章推荐
- android使用ant编译APK
- Broadcastreceiver components are not allowed to bind to services in android
- Android Service Security
- Android的IPC机制(四)—— Messenger的使用及源码分析
- Android Content Provider Security
- Android实现自定义圆形进度条
- Android Activtity Security
- AlertDialog点击自定控件关闭
- Android Broadcast Security
- Android-蓝牙聊天代码解析
- Android Logcat Security
- com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process
- android快速开发框架xUtils
- Android Notes By Lenhart
- Android学习的纯控件干货连接,留着慢慢学
- Android 一键直接查看Sqlite数据库数据
- android的学习资源集合
- android radiogroup 中 某个radiobutton设置不可更改设置 但是点击会有提示 的 方法
- Android 打开和隐藏软键盘
- Android Service学习总结(上)