Search code examples
androidandroid-viewandroid-xmlandroid-buttonnine-patch

Button with transparent background darkens in Lollipop Android


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?


Solution

  • 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