question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ExtendedFloatingActionButton] background clip animation does not work

See original GitHub issue

Description: When custom background is set to clip drawable, or any containing like below

<clip
    android:clipOrientation="horizontal"
    android:gravity="start">
    <shape android:shape="rectangle">
          <corners
                android:bottomLeftRadius="?attr/progressingButtonCornerRadius"
                android:bottomRightRadius="?attr/progressingButtonCornerRadius"
                android:topLeftRadius="?attr/progressingButtonCornerRadius"
                android:topRightRadius="?attr/progressingButtonCornerRadius" />
           <solid android:color="?attr/progressingButtonBackground" />
    </shape>
</clip>

cliping does not work; setting the same for normal button does work.

Expected behavior: With ExtendedFloatingActionButton image

With simple Button image

Source code: background drawable

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners
                android:bottomLeftRadius="25dp"
                android:bottomRightRadius="25dp"
                android:topLeftRadius="25dp"
                android:topRightRadius="25dp" />
            <solid android:color="@color/white" />
            <stroke android:width="4dp" android:color="#D81B60"/>
        </shape>
    </item>
    <item android:id="@+id/clipItem">
        <clip
            android:clipOrientation="horizontal"
            android:gravity="start">
            <shape android:shape="rectangle">
                <corners
                    android:bottomLeftRadius="25dp"
                    android:bottomRightRadius="25dp"
                    android:topLeftRadius="25dp"
                    android:topRightRadius="25dp" />
                <solid android:color="#D81B60" />
            </shape>
        </clip>
    </item>
</layer-list>

background replacement

val drawable = prepareDrawable(R.drawable.extended_progressive_bg, R.style.ProgressingButton_Cancel) as LayerDrawable
clipDrawable = drawable.findDrawableByLayerId(R.id.clipItem)
ext_btn.background = drawable

ext_btn is either Button or com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton. Please notice that Button != com.google.android.material.button.MaterialButton; (when I replaced Button with it, it also did not work)

animation

val animator = TimeAnimator()
val maxTime = 10 * 1000
animator.setTimeListener { _, totalTime, _ ->
    clipDrawable.level = (totalTime.toDouble() / maxTime * 10000).toInt()
    f (totalTime > maxTime) {
         animator.cancel()
     }
}
animator.start()

Android API version: 30

Material Library version: 1.4.0

Device: Pixel 4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
drchencommented, Sep 20, 2021

I think you need to get the clip drawable “after” you set the background.

I didn’t know the exact reason but it seems after you set the view background the returned clip drawable changes.

0reactions
Azbesciakcommented, Sep 21, 2021

Yeah… Thank you. For all with the same problem, below works:

val drawable = prepareDrawable(R.drawable.extended_progressive_bg, R.style.ProgressingButton_Cancel) as LayerDrawable
ext_btn.background = drawable
clipDrawable = drawable.findDrawableByLayerId(R.id.clipItem)

I tried with stacking backgrounds to have the ripple effect from the original one, but it did not work at the first time, I did not go deeper; I suppose it is needed to add ripple by yourself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FloatingActionButton with text instead of image - Stack Overflow
Thanks to all. Here is easy workaround which I found for this question. Works correctly for Android 4+, for Android 5+ is added...
Read more >
[ExtendedFloatingActionButton] shrink not work with ... - GitHub
My workaround is to wrap the MotionLayout into another Layout where I put the ExtendedFAB and then use a TransitionListener in the MotionLayout ......
Read more >
Expandable Floating Action Button - Android Studio Tutorial
Your browser can 't play this video. ... Watch my video about to learn how to create Custom Animation resource files: https://youtu.be/ ...
Read more >
[1P8] Observations to the new design - 1Password Community
New and Edit buttons are odd. Why not use an extended floating action button? Bigger and easier to press, and more in line...
Read more >
Buttons: floating action button - Material Design
The extend animation extends the FAB to show the text and the icon. ... Regular FABs are FABs that are not expanded and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found