0

I want to create imageviews with curved edges like this diagram

enter image description here

I want to be able to change the colours of the border at runtime. How can I achieve this?

mungaih pk
  • 1,809
  • 8
  • 31
  • 57
  • Combine [this](https://github.com/MostafaGazar/CustomShapeImageView) with a shape. – Phantômaxx Mar 02 '15 at 14:06
  • This may help you to draw and change the stoke color at run-time. [1]: http://stackoverflow.com/questions/13585496/change-shape-border-color-at-runtime – Hanan Mar 02 '15 at 14:06

1 Answers1

1

Define the image view as this and give the background the rectangle shape.

 <ImageView
     android:id="@+id/image"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@drawable/rectangle"
     android:src="@drawable/ic_launcher" />

The rectangle is defined as follows.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/white" />
    <size
        android:width="100dp"
        android:height="100dp" />
    <stroke
        android:width="10dp"
        android:color="@android:color/black" />
    <corners android:radius="50dp"/>
</shape>

Finally, from your code, set the color this way:

    ImageView image = (ImageView) findViewById(R.id.image);
    GradientDrawable background = (GradientDrawable) image.getBackground();
    background.setStroke(10, getResources().getColor(android.R.color.black));
pepan
  • 678
  • 6
  • 11