android 5.0 -- Palette
Android -- 5.0
2023-09-14 08:59:01 时间
Palette用来从图片资源中获取颜色内容。
下面是个对颜色值使用的工具类:
public class PaletteUtils { public static int getColorWithDefault(Palette palette, int defaultColor) { Palette.Swatch currentItem = null; if (currentItem == null) {
//充满活力的颜色 currentItem = palette.getVibrantSwatch(); } if (currentItem == null) {
//充满活力的暗色调 currentItem = palette.getDarkVibrantSwatch();; } if (currentItem == null) {
//充满活力的亮色调 currentItem = palette.getLightVibrantSwatch(); } if (currentItem == null) { //柔和色调
currentItem = palette.getMutedSwatch(); } if (currentItem == null) {
//柔和暗色调 currentItem = palette.getDarkMutedSwatch(); } if (currentItem == null) {
//柔和亮色调 currentItem = palette.getLightMutedSwatch(); } return currentItem != null ? currentItem.getRgb() : defaultColor; } private PaletteUtils() { throw new AssertionError(); } }
如下是从bitmap里面获取颜色内容,get是获取不同色调的颜色,然后通过getRgb()获取程序所需的真实颜色内容,
palette.generateAsync是异步的获取bitmap里面颜色的方法,里面的操作是在异步线程中的操作。
Palette.generate()不是异步的,主线程中操作。
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), SuperAwesomeCardFragment.getBackgroundBitmapPosition(position)); // Palette的部分 Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { /** * 提取完之后的回调方法 */ @Override public void onGenerated(Palette palette) { Palette.Swatch vibrant = palette.getVibrantSwatch(); /* 界面颜色UI统一性处理,看起来更Material一些 */ mPagerSlidingTabStrip.setBackgroundColor(vibrant.getRgb()); mPagerSlidingTabStrip.setTextColor(vibrant.getTitleTextColor()); // 其中状态栏、游标、底部导航栏的颜色需要加深一下,也可以不加,具体情况在代码之后说明 mPagerSlidingTabStrip.setIndicatorColor(colorBurn(vibrant.getRgb())); mToolbar.setBackgroundColor(vibrant.getRgb()); if (android.os.Build.VERSION.SDK_INT >= 21) { Window window = getWindow(); // 很明显,这两货是新API才有的。 window.setStatusBarColor(colorBurn(vibrant.getRgb())); window.setNavigationBarColor(colorBurn(vibrant.getRgb())); } } });
相关文章
- [Android Pro] android root权限破解分析
- Appium移动自动化测试(三)--安装Android模拟器
- Android中如何使用GridView
- Android中如何使用Listview
- android连接打印机
- android 5.0 -- Activity 过渡动画
- android 5.0新特性学习--视图阴影
- android 5.0新特性学习--CardView
- android 5.0新特性学习--RecyclerView
- 我的android学习脚步----------- 的第一个应用
- 《android开发艺术探索》读书笔记(十一)--Android的线程和线程池
- 《android开发艺术探索》读书笔记(十)--Android的消息机制
- studio--如何将Eclipse中的项目迁移到Android Studio 中
- 转--一款漂亮实用的Android开源日期控件timessquare
- android 5.0新特性学习--视图轮廓
- android 5.0新特性学习--RecyclerView
- 《Android进阶之光》--网络编程与网络框架
- 《Android源码设计模式》--Builder模式
- Android SQLite服务--创建、增删改查
- Android GIS开发系列-- 入门季(3) GraphicsLayer添加点、线、面
- Android 7.1预装系统preinstall目录可卸载应用
- Android【报错】java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Bu
- Android C++--类型转换
- Android app快速定位耗时代码的方法
- Android android studio 项目放在源码中编译
- Android OpenGL ES(四)----调整屏幕的宽高比
- 【Android Gradle 插件】组件化中的 Gradle 构建脚本实现 ⑤ ( 优化 Gradle 构建脚本 | 构建脚本结构 | 闭包定义及用法 | 依赖配置 | android 块配置 )
- Android OkHttp完全解析 --zz
- Android 开发 --Unable to resolve target 'android-19'
- Android 基础知识
- The minCompileSdk (33) specified in a dependency‘s AAR metadata (META-INF/com/android/build/gradle/a
- Android Studio 安装与配置
- Android 蓝牙音箱开发