【问题标题】:How to get appropriate title text color with palette如何使用调色板获得适当的标题文本颜色
【发布时间】:2016-06-23 11:21:18
【问题描述】:

这就是我使用时发生的事情

我想从调色板对象中获得赞美文本颜色

我试过了,但没有达到预期的效果 调色板.getVibrantSwatch().getTitleTextColor();

请帮助我展示使用调色板获取文本颜色的正确方法

【问题讨论】:

  • 试试getBodyTextColor()
  • 你想达到什么目的?你尝试了什么?这对我来说不是一个明确的问题。
  • 与 getBodyTextColor() #Ahmed 的结果相同

标签: java android palette


【解决方案1】:

从提供的资源生成颜色需要一些时间,这就是为什么您应该异步使用 Pallet。

位图 bm = BitmapFactory.decodeResource(getResources(), VersionData.getOsDrawable(osVersion));

    Palette.PaletteAsyncListener listener = new Palette.PaletteAsyncListener() {
        public void onGenerated(Palette palette) {
            Log.d("Palette", "Palette has been generated");
            TextView tv1 = (TextView) findViewById(R.id.tv1);
            TextView tv2 = (TextView) findViewById(R.id.tv2);

// use initialized Pallet here                  tv1.setBackgroundColor(palette.getVibrantColor(0x000000));

tv2.setBackgroundColor(palette.getVibrantColor(0x000000));

            //Noticed the Expanded white doesn't show everywhere, use Palette to fix this
            collapsingToolbar.setExpandedTitleColor(palette.getVibrantColor(0x000000));
        }
    };

    // Start this Async, because it takes some time to generate
    Palette.from(bm).generate(listener);

有一个优秀的 Material Design 示例项目 https://github.com/mwolfson/android-historian

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多