GithubHelp home page GithubHelp logo

irmobydick / floatingactionbutton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makovkastar/floatingactionbutton

0.0 1.0 0.0 5.38 MB

Android Google+ like floating action button

License: MIT License

floatingactionbutton's Introduction

FloatingActionButton

Android Arsenal

Description

Android Google+ like floating action button which reacts on the list view scrolling events. Becomes visible when the list view is scrolled up and invisible when scrolled down.

Demo

Demo

FloatingActionButton Demo on Google Play Store

Integration

1) Add as a dependency to your build.gradle:

dependencies {
    compile 'com.melnykov:floatingactionbutton:1.0.5'
}

2) Add the com.melnykov.fab.FloatingActionButton to your layout XML file. The button should be placed in the bottom right corner of the screen. The width and height of the floating action button are hardcoded to 56dp for the normal and 40dp for the mini button as specified in the guidlines.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:fab="http://schemas.android.com/apk/res-auto"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

    <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    <com.melnykov.fab.FloatingActionButton
            android:id="@+id/button_floating_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_margin="16dp"
            android:src="@drawable/ic_action_content_new"
            fab:fab_colorNormal="@android:color/holo_red_dark"
            fab:fab_colorPressed="@android:color/holo_red_light"/>
</FrameLayout>

3) Attach the ListView or the GridView to the button in the Java code:

ListView listView = (ListView) findViewById(android.R.id.list);
FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.button_floating_action);
floatingActionButton.attachToListView(listView);

FloatingActionButton extends android.widget.ImageButton so it has all methods the latter has.

4) Add the namespace xmlns:fab="http://schemas.android.com/apk/res-auto" to your layout file.

  • Set the button type (normal or mini) via the fab_type xml attribute (default is normal):

    fab:fab_type="mini"

    or

    floatingActionButton.setType(FloatingActionButton.TYPE_MINI);
  • Set the normal and pressed colors via the xml attributes:

    fab:fab_colorNormal="@android:color/holo_red_dark"
    fab:fab_colorPressed="@android:color/holo_red_light"

    or

    floatingActionButton.setColorNormal(getResources().getColor(android.R.color.holo_red_dark));
    floatingActionButton.setColorPressed(getResources().getColor(android.R.color.holo_red_light));
  • Enable/disable the button shadow with the fab_shadow xml attribite (it's enabled by default):

    fab:fab_shadow="false"

    or

    floatingActionButton.setShadow(false);
  • Show/hide the button expliciltly:

    floatingActionButton.show();
    floatingActionButton.hide();
    
    floatingActionButton.show(false); // Show without an animation
    floatingActionButton.hide(false); // Hide without an animation

5) Set an icon for the FloatingActionButton using android:src xml attribute. Use drawables of size 24dp as specified by guidlines. Icons of desired size can be generated with Android Asset Studio.

Changelog

Version 1.0.5:

  • Updated shadow to more accurately match the material design spec;

Version 1.0.4:

  • Allow a custom OnScrollListeners to be attached to a list view;
  • Work properly with list of different height rows;
  • Ignore tiny shakes of fingers.

Version 1.0.3:

  • Add methods to show/hide without animation;
  • Fix show/hide when a view is not measured yet.

Applications using FloatingActionButton

Please ping me if you would like to be added here.

Icon Application

License

The MIT License (MIT)

Copyright (c) 2014 Oleksandr Melnykov

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.

floatingactionbutton's People

Contributors

makovkastar avatar paulmaddox avatar stephanebg avatar viliuskraujutis avatar zeliret avatar

Watchers

 avatar

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.