Reputation: 167
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.
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
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
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
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