I'm using Material Buttons in my project and trying to set backgroundTint with alpha value.
<!-- background_tint.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/black" android:alpha="0.60"/>
</selector>
<!-- activity_main.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Sign in"
app:backgroundTint="@color/background_tint" />
</LinearLayout>
The resulting button however looks weird while in normal state and even weirder while pressed.
I don't see this issue when I set backgroundTint to specific shade of gray such as #777777. Why does this happen with alpha value?
CSS Code: In this section, we will design the button using CSS property. We will use the background-color: transparent; property to set the button with transparent look. Complete Code: In this section, we will combine the above two sections to create a transparent background button.
I try change color to MaterialButton with this code: var materialButton = findViewByid(R.id....) as MaterialButton materialButton. setBackgroundColor( ContextCompat. getColor(this@MyActivity, R.
“what is backgroundtint in android” Code Answer Friends, Background Tint Mode in android studio is use to down the background color and you can add , multiply , opacity and something else mode use to color overlapping on any background , and its support only API Level 5.0 and upper version.
MaterialButton manages its own background drawable, and setting a new background means MaterialButton can no longer guarantee that the new attributes it introduces will function properly. If the default background is changed, MaterialButton cannot guarantee well-defined behavior.
We had the same issue with partially opaque elevated material views.
Simply adding android:stateListAnimator="@null"
removed the visible shadow artifacts.
We also set the elevation
to 0dp
which I don't think is required.
You just need to change the style property of Material Button.
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With