android:TextView基于图像的文本颜色;

时间:2018-07-21 11:33:22

标签: android colors textview imageview

我在ImageView的顶部有一个TextView。

enter image description here

图像是从服务器加载的。图像可能有亮/暗区域。所以我想根据图像更改文本颜色。所以我试过了color palatte api

Picasso.get().load(pic).placeholder(R.drawable.holder).into(iv, new com.squareup.picasso.Callback() {
    @Override
    public void onSuccess() {
        Bitmap bitmap = ((BitmapDrawable) iv.getDrawable()).getBitmap();
        Palette.from(bitmap).generate(palette -> {
            Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();

            if (vibrantSwatch != null) {            
                name.setTextColor(vibrantSwatch.getBodyTextColor());
                job.setTextColor(vibrantSwatch.getBodyTextColor());
            }

        });
    }

    @Override
    public void onError(Exception ex) {

    }
});

它适用于某些图像。在其他情况下,VisitiveSwatch为null或根本不返回正确的颜色。有人对此有完美的解决方案吗?预先感谢。

0 个答案:

没有答案
相关问题