leandroBorgesFerreira / LoadingButtonAndroid

A button to substitute the ProgressDialog
MIT License
1.95k stars 214 forks source link

CircularProgressButton doesn't work with gradient_button.xml #28

Closed Lexycon closed 5 years ago

Lexycon commented 6 years ago

The CircularProgressButton won't work correctly with my gradient_button.xml background. In fact it doesn't change the color when I click on it. So it simply doesn't execute the android:state_pressed="true" part... Using this gradient_button.xml for a default button, it works perfectly.

layout_main.xml

<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
        android:id="@+id/buttonCircle"
        android:text="Register Device"
        app:spinning_bar_color="#fff"
        app:spinning_bar_padding="6dp"
        app:spinning_bar_width="4dp"
        app:initialCornerAngle="24dp"
        style="@style/button"
        />

style.xml

    <style name="button">
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">20sp</item>
        <item name="android:layout_marginTop">30dp</item>
        <item name="android:background">@drawable/gradient_button</item>
        <item name="android:paddingStart">35dp</item>
        <item name="android:paddingEnd">11dp</item>
        <item name="android:drawableEnd">@drawable/ic_navigate_next_24dp</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

gradient_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid
                android:color="@color/lightgreen" />

            <corners
                android:radius="24dp" />

            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid
                android:color="@color/green" />

            <corners
                android:radius="24dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>
leandroBorgesFerreira commented 6 years ago

I will take a look at this

csdodd commented 6 years ago

If I disable the call to setBackground (this line: https://github.com/leandroBorgesFerreira/LoadingButtonAndroid/blob/master/loading-button-android/src/main/java/br/com/simplepass/loading_button_lib/customViews/CircularProgressButton.java#L148) then selectors work, but I have no idea what consequences this has.

leandroBorgesFerreira commented 6 years ago

Hi. This button doesn't support change of state in a selector. This is due the fact that the only drawable that the corners can be set is the gradient drawable. So the selector is cast to gradient drawable.