【问题标题】:Color from Circle ImageView来自圆形 ImageView 的颜色
【发布时间】:2017-04-22 04:57:58
【问题描述】:

我创建圆形ImageView,下一个代码

ImageView colorView = (ImageView) findViewById(R.id.chooseColorEdit);
colorView.setBackgroundColor(Color.MAGENTA);
Drawable drawable = getResources().getDrawable(R.drawable.circle);
drawable.setColorFilter(Color.GRAY, PorterDuff.Mode.SRC);
colorView.setBackground(drawable);

如何从 imageView 获取颜色?

【问题讨论】:

标签: android


【解决方案1】:

你可以得到如下代码的颜色

Drawable background = colorView.getBackground();
if (background instanceof ColorDrawable) {
   Color color = ((ColorDrawable) background).getColor();
 }

【讨论】:

  • @Eren_Utku 抱歉,我的背景不是 ColorDrawable
【解决方案2】:

1.ImageView获取ColorDrawable

ColorDrawable colorDrawable = (ColorDrawable) colorView.getBackground();

2. 获取color 使用:

colorDrawable.getColor(); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-13
    • 2010-12-31
    • 2011-07-28
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多