4

I currently have the following xml file in my /res/drawable folder:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<solid
    android:color="@color/transparent_white" />

<stroke
    android:width="1dip"
    android:color="@color/light_gray" />
</shape>

Sometimes I would like the background to be white, gray, blue etc. depending on the item I am trying to border. Is there a way to do this without creating n number of xml files where the only difference is the color of the solid attribute?

Sheridan Gray
  • 698
  • 1
  • 9
  • 23

1 Answers1

0

you could do this by dynamically declaring the shape and changing the color at runtime.

ShapeDrawable shapeDrawable= new ShapeDrawable();
shapeDrawable.setShape(new RectShape());
shapeDrawable.getPaint().setColor(<your color>);

((TextView) row.findViewById(<your viewid>)).setBackgroundDrawable(shapeDrawable);
Durga Mohan
  • 1,110
  • 9
  • 11
  • I understand what you are saying, but I was looking for a solution using `XML`, not `Java` because its very simple for that. I want XML solution because it makes coding easy. – Ultimo_m Jun 08 '15 at 22:19