vvThat
vvThat

Reputation: 167

how can I change LinearLayout's color with round corner in runtime?

I'm trying to draw LinearLayout with round corner.

I want changing this layout's color in runtime, using Colorfilter. but ColorFilter can't apply layout, only apply view..

I don't know how can achieve this.

  1. draw LinearLayout wiht round corner
  2. and change layout's color in runtime

how can I do that? I should be very grateful to you if you might help me :) (Sorry for short English, because I'm foreigner :| )

Upvotes: 2

Views: 2451

Answers (3)

Akhil
Akhil

Reputation: 158

I think you need to change the background color of linear layout with round corner dynamicaly right?

GradientDrawable gd = new GradientDrawable();
    gd.setColor(Color.parseColor("Your color code"));
    gd.setCornerRadius(60);
    your_layout.setBackgroundDrawable(gd);

Upvotes: 5

Krunal Indrodiya
Krunal Indrodiya

Reputation: 792

Please follow this code,

//this code in your activity, java file

LinearLayout linearLayout=(LinearLayout)findViewById(R.id.your_linear_layout_id);
linearLayout.setBackgroundResource(R.drawable.drawable_file_in_xml);

//drawable_file_in_xml

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <gradient android:startColor="#444444" android:endColor="#202020" android:angle="-90"/>
    <corners android:radius="2dp"/> 
</shape>

In this code you can set round corner <corners android:radius="2dp"/>.

Upvotes: 0

Carsten
Carsten

Reputation: 806

If you take this example it shows how to apply a round corner and shadow using an xml drawable: Android LinearLayout : Add border with shadow around a linearLayout

You can apply this background to your layout during runtime with

yourLayout.setBackgroundResource(int resid);

Upvotes: 0

Related Questions