Issue
I want to set ColorFilter for Button background. Here is what I have done:
Drawable buttonBackground = ContextCompat.getDrawable(this, R.drawable.shape_rect_stroke);
buttonBackground.setColorFilter(ContextCompat.getColor(this, R.color
.colorPrimary), PorterDuff.Mode.ADD);
btnSignIn.setBackground(buttonBackground);
shape_rect_stroke.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/colorWhite"/>
<solid android:color="@android:color/transparent"/>
</shape>
By doing this, I am getting,
But i want this:
My xml file is working fine but i want to change the stroke
color pragmatically, leaving solid
color as transparent. so i can use same xml for different color button background...
Please suggest me how can i get this. Thanks!
Solution
Finally i have done this by doing this:
GradientDrawable drawable = (GradientDrawable) btnSignIn.getBackground();
drawable.setStroke(3, ContextCompat.getColor(this,R.color.colorPrimary));
Answered By - Hello World
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.