Giter VIP home page Giter VIP logo

fabtoolbar's Introduction

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.

fabtoolbar's People

Contributors

fafaldo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fabtoolbar's Issues

How to match the Snackbar?

As we know, in the Material Design, when we click the FAB button, then the Snackbar appear and Fab button start to rise, but I find I can realize this effect by your FABToolbar.

I'm so sorry that my Chinese style English, because I'm a Chinese.

Hide fab if Show it

Hi, thanks for this library. i have a question please answer to me ❤️
i want hide fab when isShow it, and i want write this code in onBackPress method when write this code show me error :

    @Override
    public void onBackPressed() {
        if (fabToolbar.show()) {
            fabToolbar.hide();
        } else {
            onBackPressed();
        }
    }

Error image has attached.
31

please help me for fix this problem. thanks my dear friend ❤️

wrong animation if use AppBarLayout

Hi,

i'm using AppBarLayout in MainActivity

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        >

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</android.support.design.widget.AppBarLayout>

and FABToolbarLayout in fragment from first tab 'Translation'.

transition animation button in the toolbar is not the same as in your example:

ezgif com-video-to-gif

if i'm remove AppBarLayout and tabs, then animation getting correct.

Performance issues due to ToolbarLayout

Today I discovered performance issues regarding the library (bad scrolling-performance in lists, ripple highlighting freezes etc).

Without the FABToolbar the issues are gone. I digged deeper and discovered that if I remove only the toolbarLayout from my View-Hierarchy it works as well.

Thus I guess it has to do with toolbarLayout.getViewTreeObserver().addOnGlobalLayoutListener which is never removed.

Examples please

Could you please add an example app or more java code to implement the FABToolbar layouts??
i am totally new to this and this looks like a pretty awesome library, it will be really helpful.. @fafaldo

wrap_content support

Now the view with id "fabtoolbar_toolbar" does not support wrap_content,which make it's hard to contain a view like edittext in it
untitled

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...");
         }
     }
});

Anchor property not working for the layout

I placed the reveal layout in a CoordinateLayout so it can move with AppBarLayout but the problem is I cant anchor the floating button and Its revealing toolbar to the AppBarLayout. Also the anchor property for the parent layout doesn't work correclty

The icon of the fab is shown as background for the toolbar.

This problem occurs when the following actions are executed:

  1. Change the icon of the fab with fab.setImageResource(int res)
  2. Call fabLayot.Show() to transform the fab into toolbar.
  3. Now the new icon of the fab will be animated and also stay as background for the toolbar

I have tested this behaviour on:

  • Nexus 5 (Android 6.0.1)
  • Samsung Galaxy Note 3 Lite (Android 5.1.1)
  • Nexus 10 emulator (Android 4.4)

If android:background element is set for the toolbar, then the fab's icon won't stay as background for the toolbar, but the animation issue still remains.

This issue might be related to Issue on Sony Devices with FabToolbar, but this is a problem for more than just Sony devices.

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);
                            }

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.

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?

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.

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.

View IDs constricted

It'd be great if you let the devs use their own ids for the views instead of having them hard coded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.