Floating Action Button transforming into toolbar

Overview

FABToolbar

Maven Central Android Arsenal

An implementation of Google design, with Floating Action Button transforming into toolbar.

Illustration of behavior

Features:

  • morphing Floating Action Button (or any other view that extends ImageView) into custom toolbar
  • FAB image fade-out animation
  • toolbar elements fade-in animation
  • toolbar elements translation animation

How to use

Import dependency using Gradle:

compile 'com.github.fafaldo:fab-toolbar:1.2.0'

In order to use FABToolbar you need to implement following view hierarchy in your XML layout file:

|
|->FABToolbarLayout
	|
	|-> Some container (that is, or extends RelativeLayout)
	|	|
	|	|-> Your FAB (or other view that extends ImageView)
	|	
	|-> Your Toolbar (view that extends ViewGroup)
		|
		|-> Your elements
		...

Starting from version 1.1.0 views do NOT have to be assigned a static ID. Instead try referencing them in XML attributes in FABToolbarLayout, as shown below.

Example implementation:

<com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout
	android:id="@+id/fabtoolbar"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	app:showDuration="600"
	app:hideDuration="200"
	app:horizontalMargin="30dp"
	app:verticalMargin="30dp"
	app:fadeInFraction="0.2"
	app:fabId="@+id/fabtoolbar_fab"
	app:containerId="@+id/fabtoolbar_container"
	app:fabToolbarId="@+id/fabtoolbar_toolbar">

	...
	
	<RelativeLayout
		android:id="@+id/fabtoolbar_container"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_alignParentBottom="true"
		android:layout_alignParentRight="true">

		<android.support.design.widget.FloatingActionButton
			android:id="@+id/fabtoolbar_fab"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			app:fabSize="normal"
			android:src="@drawable/abc_ic_menu_share_mtrl_alpha"/>

	</RelativeLayout>

	<LinearLayout
		android:id="@+id/fabtoolbar_toolbar"
		android:layout_width="match_parent"
		android:layout_height="70dp"
		android:layout_alignParentBottom="true"
		android:orientation="horizontal">

		<ImageView
			android:id="@+id/one"
			android:layout_width="0dp"
			android:layout_height="match_parent"
			android:layout_weight="1"
			android:scaleType="centerInside"
			android:src="@drawable/test"/>
		...
		
	</LinearLayout>

</com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout>

To open toolbar call method

show();

To close toolbar call method

hide();

In case of other problems with implementation see example included in this repository.

Parameters:

You can control these parameters via XML:

<attr name="showDuration" format="integer"/>      	//show animation duration (in ms), default: 600 ms
<attr name="hideDuration" format="integer"/>      	//hide animation duration (in ms), default: 600 ms
<attr name="verticalMargin" format="dimension"/>    //FAB vertical margin (in dp), default: 100 px
<attr name="horizontalMargin" format="dimension"/>  //FAB horizontal margin (in dp), default: 100 px
<attr name="fadeInPivotX" format="dimension"/>    	//toolbar elements translation animation pivot X (in dp), default: 1/2 toolbar width
<attr name="fadeInPivotY" format="dimension"/>    	//toolbar elements translation animation pivot Y (in dp), default: 1/2 toolbar height
<attr name="fadeInFraction" format="float"/>      	//percent of translation animation, between element position and pivot point (float 0.0-1.0), default: 0.2
<attr name="fabId" format="reference"/>			  	//reference to the FAB view
<attr name="containerId" format="reference"/>	  	//reference to the FAB container view
<attr name="fabToolbarId" format="reference"/>    	//reference to the FAB toolbar view
<attr name="fabDrawableAnimationEnabled" format="boolean"/> //enable or disable FAB cross-fade animation, default: true

Changelog

  • 1.2.0 - most of the issues reported by users fixed - toolbar shadow, wrap_content height, side alignment, OnClickListener etc.
  • 1.1.0 - view id constraints removed, removed container layout, fixed FAB shadow problems
  • 1.0 - initial release

License

FABToolbar for Android

The MIT License (MIT)

Copyright (c) 2015 Rafał Tułaza

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Issue on Sony Devices with FabToolbar

    Issue on Sony Devices with FabToolbar

    Having an issue with Sony devices in particular (Z3 & Z3 Compact) where the icon of the fab is not disappearing from the background when expanded. It doesn't happen on a Galaxy Nexus running JellyBean or Nexus 5 running Marshmallow. The video below demonstrates the issue... http://clients.intohand.com/demo/XperiaProblem.mov

    opened by elroid 4
  • Unable to listen to fab click

    Unable to listen to fab click

    Trying to listen to click event on fabtoolbar_fab (FloatingActionButton) to call fabToolbar show() only when some condition is met.

    Problem: My onClickListener isn't getting called when Fab is clicked.

    findViewById(R.id.fabtoolbar_fab).setOnClickListener(new View.OnClickListener() {
        @Override public void onClick(View view) {
             Log.d("mlog", "My Click"); // Doesn't trigger
             if ( isLoaded() ) { 
                 fabToolbar.show();
             } else {
                 showSnackBar("Fetching newsfeed...");
             }
         }
    });
    
    opened by androidfanatic 2
  • Add check SDK version

    Add check SDK version

    in FABToolbarLayout.java need add check SDK version in 185 line for support Android SDK version 15:

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                                    fabContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                                } else {
                                    fabContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                                }
    
    opened by askarsyzdykov 2
  • Why to limit it to API 16 when you can make for earlier APIs?

    Why to limit it to API 16 when you can make for earlier APIs?

    Hi, you can use if (Build.VERSION.SDK_INT < 16) { fabContainer.getViewTreeObserver().removeGlobalOnLayoutListener(this); fab.setVisibility(VISIBLE); } else { fabContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this); fab.setVisibility(VISIBLE); } to make it compatible for <16 sdk versions.

    opened by hirakchhatbar 1
  • Can't change the Color

    Can't change the Color

    Hello, I have tried to set background color of "FloatingActionButton" and the animation of the layout but I can't do it! Can you please tell me how can I do that?

    opened by sohilmemon 1
  • hide() does not bring floating action button is not at same place

    hide() does not bring floating action button is not at same place

    if layout of FloatingActionButton is

    android:layout_alignParentTop="true" android:layout_alignParentRight="true"

    when we call layout.hide() then toolbar hides but FAB apears too much up. even half is cut by topbar.

    opened by NomanLatif 3
  • BUG: issues FAB that morphs into android.support.v7.widget.Toolbar

    BUG: issues FAB that morphs into android.support.v7.widget.Toolbar

    Hi,

    I set FAB that morphs into android.support.v7.widget.Toolbar:

    <com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/fabtoolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:containerId="@+id/fabtoolbar_container"
        app:fabId="@+id/fabtoolbar_fab"
        app:fabToolbarId="@+id/fabtoolbar_toolbar"
        app:fadeInFraction="0.2"
        app:hideDuration="200"
        app:horizontalMargin="30dp"
        app:showDuration="600"
        app:verticalMargin="30dp"
        tools:showIn="@layout/activity_main">
    
        <RelativeLayout
            android:id="@+id/fabtoolbar_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:clipChildren="false"
            android:clipToPadding="false">
    
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabtoolbar_fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_margin="@dimen/fab_margin"
                android:src="@drawable/ic_mode_edit_white_24dp"
                app:fabSize="mini" />
    
        </RelativeLayout>
    
        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/fabtoolbar_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:minHeight="?attr/actionBarSize"
            app:theme="@style/Base.Theme.AppCompat.CompactMenu">
    
            <Spinner
                android:id="@+id/add_spinner"
                android:layout_width="50dp"
                android:layout_height="match_parent" />
            <!--android:background="@android:drawable/btn_default"-->
    
        </android.support.v7.widget.Toolbar>
    
    </com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout>
    

    I have two issues:

    1. The fab that morphs into toolbar shows as very small (by factor of 2) see screenshot
    2. After each morph cycle (fab-->toolbar-->fab) the fab moves to left some 5dps and then completely disappears so you can't tap on it.

    The cause for this is 50dp size of the spinner. If I set it to 70dp everything works fine.

    opened by greg-stein 1
  • Ripple effect disappear when onClick added in the XML for ImageView

    Ripple effect disappear when onClick added in the XML for ImageView

    Hello, when adding android:onClick="someClick" to the ImageView in the XML, the ripple effect disappearing after the first click. How can this be fixed?

    opened by Zerakul 0
  • Start showing toolbar instead Float Button

    Start showing toolbar instead Float Button

    I want to do the same example showed on Material Design doc (on scroll transform the Toolbar on Float Button). I tried to do this with this lib but when I start the Activity with fABToolbarLayout.show() (after the Activity render the screen) the lib do the expand animation.

    opened by fesnasser 0
  • Added possibility to display the toolbar as the default view

    Added possibility to display the toolbar as the default view

    Usage:

    <!-- layout.xml -->
    
        <com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout
            ...
            app:defaultView="toolbar">
            <!--  app:defaultView values: "toolbar" or "fab" (default: fab) -->
    
        <!-- ... -->
        </com.github.fafaldo.fabtoolbar.widget.FABToolbarLayout>
    
    opened by zoltanbalint 0
Owner
Rafał Tułaza
Rafał Tułaza
Android Sample Project with Material Design and Toolbar.

AndroidMaterialDesignToolbar -- PROJECT IS NOT SUPPORTED Android Sample Project with Material Design and Toolbar. Project use Appcompat library for ma

kemal selim tekinarslan 713 Nov 11, 2022
Using material toolbar sample.

MaterialToolbarSample Using material toolbar sample. Handled rtl & ltr support (I wanted to display toolbar itself ltr, but the menus based on rtl or

Masoud Maleki 0 Apr 23, 2022
Animated Material circular button

Material Circular Button Circular button for Android in Google Material Style How to use Clone this proyect and import the module "materialCircularBut

Adrián Lomas 217 Nov 25, 2022
Capturable - 🚀Jetpack Compose utility library for capturing Composable content and transforming it into Bitmap Image🖼️

Capturable ?? A Jetpack Compose utility library for converting Composable content into Bitmap image ??️ . Made with ❤️ for Android Developers and Comp

Shreyas Patil 494 Dec 29, 2022
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
A layout to transition between two views using a Floating Action Button as shown in many Material Design concepts

⚠ This library is no longer maintained ⚠️ FABRevealLayout A layout to transition between two views using a Floating Action Button as shown in many Mat

Tomás Ruiz-López 901 Dec 9, 2022
[] Android floating action button

DEPRECATED Use the FloatingActionButton from the support library instead. FloatingActionButton Description Android floating action button which reacts

Oleksandr Melnykov 4k Jan 5, 2023
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Dec 26, 2022
A loading animation based on Floating Action Button

FAB-Loading A loading animation based on Floating Action Button. Usage Include the LoadingView widget in your view: <io.saeid.fabloading.LoadingView

Saeed Masoumi 689 Oct 14, 2022
Android library that provides the floating action button to sheet transition from Google's Material Design.

MaterialSheetFab Library that implements the floating action button to sheet transition from Google's Material Design documentation. It can be used wi

Gordon Wong 1.6k Dec 13, 2022
Android library to animate Floating Action Button to Bottom Sheet Dialog and vice-versa

FabulousFilter Show some ❤️ and star the repo to support the project This library is the implementation of filter-concept posted on MaterialUp.com. It

Krupen Ghetiya 2.6k Jan 3, 2023
Support Floating Action Button transformation for Android

Fab Transformation This library supports Floating Action Button transformation in Material Design Guideline. Screenshot Sample App Installation Add th

Yusuke Konishi 772 Dec 4, 2022
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Dec 26, 2022
Floating Action Button for Android based on Material Design specification

FloatingActionButton Yet another library for drawing Material Design promoted actions. Features Support for normal 56dp and mini 40dp buttons. Customi

Zendesk 6.4k Jan 3, 2023
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
Kotlin Expanding Floating Action button

Kotlin-Expanding-Floating-Action_button Home Screen As you can see there is only a siongle floating button with + icon Expanding Fab button When we cl

Akshay Teli 0 Nov 3, 2021
Android library providing an implementation of the Material Design Floating Action Button Speed Dial.

Android library providing an implementation of the Material Design Floating Action Button Speed Dial.

Sanyam Mehta 6 Dec 24, 2022
Floating Action Button But Moveable And Expandalbe

MeFab todo add the maven bacge here Floating Action Button but MOVEABLE and EXPA

Hussien Fahmy 6 Dec 30, 2022
A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

Kojo Fosu Bempa Edue 114 Nov 29, 2022