LoadingButtonAndroid
LoadingButtonAndroid copied to clipboard
Button do not morph when not using background attribute
Button does not morph when we don't set any background to the button. Here is my xml
<br.com.simplepass.loading_button_lib.customViews.CircularProgressButton
android:id="@+id/welcome_signin_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/form_horizontal_margin"
android:theme="@style/AppTheme.Button"
style="@style/progressButtonStyle"
android:text="@string/welcome_signin_cta"
/>
And here is the styles applyed
<style name="AppTheme.Button">
<item name="android:textAllCaps">false</item>
<item name="android:colorButtonNormal">?attr/colorAccent</item>
<item name="android:textColor">@color/white</item>
<item name="android:textStyle">bold</item>
</style>
<style name="progressButtonStyle" parent="Widget.AppCompat.Button">
<item name="finalCornerAngle">50dp</item>
<item name="initialCornerAngle">2dp</item>
<item name="spinning_bar_color">@color/white</item>
<item name="spinning_bar_padding">4dp</item>
<item name="spinning_bar_width">2dp</item>
</style>
By the way, if we apply a background to the style, the button does not respect the material button specs. There is no elevation despite the attribute in the xml and there is nor ripple effect nor elevation when we click on the button
Thanks @mboudraa. I will take a look at this
@mboudraa This button doesn't animate by itself, you need to call startAnimation. Did you call this method??
I just tested with no background and the animation happens
Same problem here, and I found the cause. Default material buttons use a background that start with an inset
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_button_inset_horizontal_material"
android:insetTop="@dimen/abc_button_inset_vertical_material"
android:insetRight="@dimen/abc_button_inset_horizontal_material"
android:insetBottom="@dimen/abc_button_inset_vertical_material">
<shape android:shape="rectangle">
<corners android:radius="@dimen/abc_control_corner_material" />
<solid android:color="@android:color/white" />
<padding android:left="@dimen/abc_button_padding_horizontal_material"
android:top="@dimen/abc_button_padding_vertical_material"
android:right="@dimen/abc_button_padding_horizontal_material"
android:bottom="@dimen/abc_button_padding_vertical_material" />
</shape>
</inset>
and loadGradientDrawable seems to be unable to handle this inset.
Here is the result:

Hi @vincentnock. Thanks for the reply and pointing out about the inset.
This problem in not due to the fact that there's no background, or due to this inset. The spinning bar isn't aware about the padding of the button at all, so when you set a background that has padding, or when you set a padding in your button, the spinning bar will be bigger that your background because it picks the whole Views bounds. As you can see there's a padding in the material design default background.
But this is easy to fix! Always remember to set the app:spinning_bar_padding and the spinning bar will correctly fit the background.
Hmmm, if I remember correctly, the problem here is not about the spinning bar, but about the unability to perform the morph animation on a material button, because loadGradientDrawablefails to get the ShapeDrawable because of the inset.
But maybe I'm wrong, I don't have to time to test again that for the moment.
loadGradientDrawablefails can't get RippleDrawable too
Without background attribute progress bar background remains as a square.