I'm using the new material component like MaterialButton and MaterialCardView.
in my project, I need to change the material button tintBackground
programmatically.
so I use setBackgroundTintList
method to change the tint background color.
btnOk.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#20" + colorAccept)));
btnOk.setTextColor(Color.parseColor("#" + colorAccept));
as you can see I'm setting a transparent color to my material button.
I run my app in android KitKat and there was no problem as you can see in this picture.
but in Android Marshmallow, the material button Appearance changes and a shadow appear below the material button like below picture.
I try some other code but none of them works.
- first code
using below code does not change the tint background color of the button in android marshmallow.
ColorStateList colorOk = new ColorStateList(
new int[][]{
new int[]{R.attr.buttonTint}
},
new int[] {
Color.parseColor("#20" + colorAccept)
});
- second code
this code works just in KitKat and a shadow appears again in Marshmallow!
Drawable buttonDrawable = button.getBackground();
buttonDrawable = DrawableCompat.wrap(buttonDrawable);
//the color is a direct color int and not a color resource
DrawableCompat.setTint(buttonDrawable, Color.RED);
button.setBackground(buttonDrawable);
what is the problem that this shadow is showing in the newer API?