Button with transparent background darkens in Lollipop Android
Asked Answered
A

1

6

I have this button that has a 9patch background with transparent parts, but the whole button has this darken effect like this:

darken button

And here is the button xml code:

<Button
                    android:id="@+id/login_operator"
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    android:layout_margin="5dp"
                    android:background="@drawable/white_rounded"
                    android:drawableRight="@mipmap/arrow_white_down"
                    android:gravity="left|center_vertical"
                    android:text="@string/select_operator"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

Here is how this button has to look:

enter image description here

And here is the 9 patch background image:

enter image description here

This darken effect only happens on Lollipop Android version.. so does anyone knows where does this darken effect come from?

Aylsworth answered 18/8, 2015 at 9:54 Comment(0)
D
3

I ran into this issue with lollipop, for some reason the default button style has this darken effect

solved it by making this custom style:

<style name="ButtonStyle" parent="Widget.AppCompat.Button.Borderless">
    <item name="android:background">@drawable/trans</item>
</style>

assigning it to the button:

<Button
       ....
       style="@style/ButtonStyle" />

here's how to looks with and without the style:

enter image description here

Delao answered 18/8, 2015 at 10:31 Comment(1)
Thank you very much, this is the correct sollution!Aylsworth

© 2022 - 2024 — McMap. All rights reserved.