How to change shape color in image view

Now the problem starts only with setting the color of the shape. I created one rectangular shape in drawableand set it to ImageViewas follows

<LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" 
        android:layout_weight="0.15" 
        android:layout_marginRight="10dp"
        android:gravity="center_vertical">
       <ImageView 
        android:id="@+id/iv_priority"
        android:src="@drawable/case_priority"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>
</LinearLayout>

EDIT

My case_priority.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <solid android:color="#009600" />
  <size android:width="30dp"
        android:height="30dp" />
</shape>

Now I need to change the color of this shape. Actually this color comes from a web service, and I need to change it. So My Question : How can we change the color of this form programmatically. and set it to image view mode. I have done some examples in stackoverflow, but I cannot change it to an image. Please, help!!!! Thanks in advance.

EDIT:

, , . ImageView, , . , , . - , , xml , java . ,.setBackground() . , . .

+5
6

Thanx . .

My layout android:src="" to android:background="@drawable/case_priority" java n = : →

        Resources res = getResources();
        final Drawable drawable = res.getDrawable(R.drawable.case_priority);
        drawable.setColorFilter(Color.YELLOW, Mode.SRC_ATOP);
        ImageView img = (ImageView)findViewById(R.id.iv_priority);
        img.setBackgroundDrawable(drawable);

. , -.

+10

android:background="#152" // or some other color code

1:

ImageView.setBackgroundColor(Color.parseColor("red")); // Or any color code like #000 , #987

2:

ImageView Imgs = (ImageView) findViewById(R.id.iv_priority);

Imgs.setBackgroundColor(Color.parseColor("ColorCode"));
+3

IimageView.setBackgroundColor( "# 152" );

+2

, , GradientDrawable:

Drawable drawable = imageView.getDrawable();
drawable.setColorFilter(Color.CYAN, PorterDuff.Mode.MULTIPLY);
0

All solutions suggest using the ImageView background. I think this is not the desired solution. The question already reflects what would be intuitive: Applying a form to an attribute src. To programmatically change the color of the form, follow these steps:

GradientDrawable drawable = (GradientDrawable) priorityImageView.getDrawable();
drawable.setColor(Color.RED);

given that the form is assigned as in the original question:

<ImageView 
    android:id="@+id/iv_priority"
    android:src="@drawable/case_priority"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"/>

It also gives the advantage that you can set the ImageView background separately from its contents.

-1
source

All Articles