zoukankan      html  css  js  c++  java
  • 安卓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>

  • 相关阅读:
    Linux基础3-1 Bash及其特性
    三、手写ORM实现数据库更新
    三、TCP协议
    一、OIS七层模型及数据传输过程
    泛型缓存原理
    树莓派公网服务器实现frp内网穿透
    Dto数据传输对象
    Ubuntu下 Nginx静态代理部署网页常见报错
    JWT权限验证
    解决传入的请求具有过多的参数,该服务器支持最多 2100 个参数
  • 原文地址:https://www.cnblogs.com/yuanting/p/4761079.html
Copyright © 2011-2022 走看看