0

While using the floating action button provided by android developer, I can't help but to wonder how exactly did they even achieve the floating action button from scratch.

1) I would like to know how exactly was the floating action button was built

2) how is the android able to animate only the plus to become something else?

This might be a repeat of other post but I have checked already and can't seem to find any post asking this same question. If you find one that ask similar question then please let me know.

My post is different from this post: How can I add the new "Floating Action Button" between two widgets/layouts because the post above only explain how to use the android FAB library and does not explain how FAB are created from scratch.

Community
  • 1
  • 1
Wowzer
  • 1,103
  • 2
  • 12
  • 26

1 Answers1

0

FloatingActionButton class mainly extends the VisibilityAwareImageButton which extends the imagebutton . So, from scratch when you start you should start from extending imagebutton. Then when you get VisibilityAwareImageButton you can create your FloatingButton class. Code for VisibilityAwareImageButton is given below

package android.support.design.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageButton;

class VisibilityAwareImageButton extends ImageButton {

private int mUserSetVisibility;

public VisibilityAwareImageButton(Context context) {
    this(context, null);
}

public VisibilityAwareImageButton(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}

public VisibilityAwareImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mUserSetVisibility = getVisibility();
}

@Override
public void setVisibility(int visibility) {
    internalSetVisibility(visibility, true);
}

final void internalSetVisibility(int visibility, boolean fromUser) {
    super.setVisibility(visibility);
    if (fromUser) {
        mUserSetVisibility = visibility;
    }
}

final int getUserSetVisibility() {
    return mUserSetVisibility;
}
} 

How they created the Floating button:

well the source code is available in below link from google

https://android.googlesource.com/platform/frameworks/support/+/master/design/src/android/support/design/widget/FloatingActionButton.java?autodive=0%2F%2F

And the VisibilityAwareImageButton code is taken from below link https://github.com/android/platform_frameworks_support/blob/master/design/base/android/support/design/widget/VisibilityAwareImageButton.java

Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32