2

I applied borders on a linear layout:

<LinearLayout
        android:id="@+id/lay1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="80"
        android:background="@drawable/linearborder2" />

and in my main activity i want to change dynamically the background color of this one, but i do that the borders fade away. So how can i do to keep these borders and change the color?

Thank you

user2137817
  • 1,825
  • 5
  • 28
  • 45

1 Answers1

0

Assuming linearborder2 is a shape drawable.You can change the color of a shape drawable dynamically. This should help with that.

Community
  • 1
  • 1
Akash
  • 631
  • 1
  • 8
  • 16
  • i tried this one:GradientDrawable sd = (GradientDrawable) tv2.getBackground().mutate(); sd.setColor(color); sd.invalidateSelf(); & this one i found on the post you gave me ShapeDrawable bgShape = (ShapeDrawable )btn.getBackground(); bgShape.getPaint().setColor(Color); but i got a null exception pointer on both – user2137817 Mar 06 '13 at 11:22