Coder Social home page Coder Social logo

android-floating-action-button's Introduction

FloatingActionButton

Yet another library for drawing Material Design promoted actions.

Features

  • Support for normal 56dp and mini 40dp buttons.

    Demo

  • Customizable background colors for normal and pressed states and icon drawable.

    Demo

  • Convenience AddFloatingActionButton class with plus icon drawn in code.

  • FloatingActionsMenu which can be expanded/collapsed to reveal multiple actions.

    Demo

  • Optional labels for buttons in FloatingActionsMenu.

    Demo

Usage

Just add the dependency to your build.gradle:

dependencies {
    compile 'com.getbase:floatingactionbutton:1.10.1'
}

To see how the buttons are added to your xml layouts, check the sample project.

Caveats

The API is extremely limited at the moment. It solves few select use cases in the app I'm working on.

Unlike some other FloatingActionButton libraries this library doesn't implement "quick return" pattern, i.e. hiding the button on scrolling down and showing it on scrolling up. That's intentional, I think that should be responsibility of another component, not the button itself.

This library is minSdkVersion=14 and if that changes, the version number will be increased, not decreased. It means that Honeycomb, Gingerbread or - gods forbid - Froyo, won't ever be supported. I won't even consider merging pull requests fully implementing support for older versions. We need to move on as Android community and focus on delivering value for 95% of users of modern Android OS instead of jumping through burning hoops to support ancient devices with ancient OS.

If you really require support for older Android versions, str4d maintains a version of this library with minSdkVersion=4.

Credits

I used FloatingActionButton library by Oleksandr Melnykov as a base for development.

Copyright and license

Copyright 2014 Zendesk

Licensed under the Apache License, Version 2.0

android-floating-action-button's People

Contributors

afollestad avatar artmoni avatar chalup avatar docx avatar fmikhail avatar johndoejr avatar narfss avatar str4d avatar ulyssesdotcodes avatar vekexasia 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  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

android-floating-action-button's Issues

Adding Library

Hi, I am new to using external libraries. I'm using Android Studio but I'm having a real difficult time adding an external library to my app. I've following the instructions here but it is just not working. Can you please provide me with a step by step guide for installing?

I'm getting ~trunk/build.gradle failed to find: com.getbase:floatingactionbutton:1.1.0

Thanks, Eric

Intended handler pattern?

Maybe I'm just slow, but things function well, but what is the intended pattern for handling a button press? onCLick handler didn't do it...

API to access the state of FloatingActionsMenu.

Expose mExpanded from FloatingActionsMenu via isExpanded.

This is required to findout the current state of floatingactionsmenu, normal pattern is to close the actionsmenu when back button is expanded or else exit the activity.

Can't use addButton() method with FloatingActionsMenu

I try to use it the way shown in the sample app, but there's no such a method in FloatingActionsMenu class. How do I set up the buttons?

buttonA = new FloatingActionButton(activity.getBaseContext());
buttonB = new FloatingActionButton(activity.getBaseContext());

 fam = (FloatingActionsMenu) fragmentLayout.findViewById(R.id.menu);

    fam.addButton(buttonA);
    fam.addButton(buttonB);

    buttonA .setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            methodA();
        }
    });

    buttonB .setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            methodB();
        }
    });

Add event interface to FloatingActionsMenu

I had need to add a scrim to the display when the Menu was open. As there wasn't anything setup for it in the code, I extended FloatingActionsMenu with the following code. That way I could optionally add an event listener in my activity for toggling the scrim.

I don't know if this is the best way to do things which is why I'm submitting an issue instead of a pull request...

import android.content.Context;

public class FloatingActionsMenu extends com.getbase.floatingactionbutton.FloatingActionsMenu {

    private OnFloatingActionMenuUpdateListener onFloatingActionMenuUpdateListener;

    public FloatingActionsMenu( Context context ) {

        this( context, null );
    }

    public void setOnFloatingActionMenuUpdateListener( OnFloatingActionMenuUpdateListener listener ) {

        onFloatingActionMenuUpdateListener = listener;
    }

    @Override
    public void toggle() {

        super.toggle();

        if( onFloatingActionMenuUpdateListener != null ) {

            onFloatingActionMenuUpdateListener.actionMenuToggled();
        }
    }

    public interface OnFloatingActionMenuUpdateListener {

        public void actionMenuToggled();
    }
}

build.graddle

I added the dependency line into my existing project graddle build file on Android Studio beta 0.8.14

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:21.0.+"
compile 'com.getbase:floatingactionbutton:1.2.0'
}

and I got this error when build. Note that I haven't even added any codes. What could I be doing wrong?

Error:Execution failed for task ':app:processDebugResources'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\vnguyen5\android-sdks\build-tools\20.0.0\aapt.exe package -f --no-crunch -I C:\Users\vnguyen5\android-sdks\platforms\android-21\android.jar -M D:\dev\MyTestApplication\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S D:\dev\MyTestApplication\app\build\intermediates\res\debug -A D:\dev\MyTestApplication\app\build\intermediates\assets\debug -m -J D:\dev\MyTestApplication\app\build\generated\source\r\debug -F D:\dev\MyTestApplication\app\build\intermediates\res\resources-debug.ap_ --debug-mode --custom-package com.vnguyen.mytestapplication -0 apk --output-text-symbols D:\dev\MyTestApplication\app\build\intermediates\symbols\debug
Error Code:
-1073741819

Support for API 9+

I have an app that has minSdkVersion 9, and I cannot use this library with it because minSdkVersion is currently set to 14. But I have manually built the library myself and have not found any problems. Is there a reason for only supporting API 14 and above? If not, could minSdkVersion be lowered?

Inconsistent view when a transparent background color is used

Using a background color with some alpha (e.g. #99fe0038) when the shadow is set to true reveals two circles: one for the floating action button and another inside (cf. image below). The latter is probably caused by the shape of the drawable that is used for creating the shadow.

It would be nice to get a circle without the inner one when a transparent background color is used.

I have also noticed that the image drawable used for the shadow isn't provided for xxxhdpi.

device-2014-11-01-182232

Change the icon on click

Is there a way to change the plus icon on clicking in the floating actions menu?..and bringing it back to the original state on clicking anywhere else in the screen?
Just like the inbox app??

Action menu with mini action buttons

I'm trying to make menu similar to the one Inbox app has. There is a large floating button which opens a menu of mini action button, but they are horizontally centered. I can't set gravity to FloatingActionsMenu since it's a ViewGroup.

Proguard config for samples

These configs should be added to proguard, else FloatingActionsMenu's + to x animation will not work

-keep class com.getbase.floatingactionbutton.** { *; }

Attach to listview?

The version that @makovkastar made has an attachToListView method for the floating action button. I don't see a method similar on FloatingActionsMenu. Am I not seeing something or was the auto hide on scroll feature deleted?

set expandDirection in the code?

Is it possible? I tried to look but didn't find any methods but maybe it was called differently? I know we could set it in the XML but it'd be nice if we could do it in the code as well..

What I'm trying to do: is to switch the direction if the device orientation changed!

Thanks.

Floating widgets

Hi!

I created some widgets that automtically place the FAB button in the correct place like guidlines say.

I will fork your project and try to PR if you think that are cool to setup in project.!

:)

Buttons are not aligned while using mini buttons, help pls

Below code give me unaligned buttons, if make all the buttons as normal buttons are aligned

<com.getbase.floatingactionbutton.FloatingActionsMenu
                android:id="@+id/fab_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                fab:fab_addButtonColorNormal="@color/fab_normal"
                fab:fab_addButtonColorPressed="@color/fab_pressed"
                fab:fab_addButtonPlusIconColor="@color/white"
                android:layout_marginBottom="16dp"
                android:layout_marginEnd="16dp"
                android:layout_gravity="bottom|right|center">

                <com.getbase.floatingactionbutton.FloatingActionButton
                    android:id="@+id/fab_more"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    fab:fab_colorNormal="@color/colorAccent"
                    fab:fab_colorPressed="@color/colorPrimaryDark"
                    fab:fab_icon="@drawable/ic_expand_less"
                    fab:fab_size="mini"
                     />

                <com.getbase.floatingactionbutton.FloatingActionButton
                    android:id="@+id/fab_manual"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    fab:fab_colorNormal="@color/colorAccent"
                    fab:fab_colorPressed="@color/colorPrimaryDark"
                    fab:fab_icon="@drawable/ic_keyboard"
                    fab:fab_size="mini" />

                <com.getbase.floatingactionbutton.FloatingActionButton
                    android:id="@+id/fab_scan"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    fab:fab_colorNormal="@color/colorAccent"
                    fab:fab_colorPressed="@color/colorPrimaryDark"
                    fab:fab_icon="@drawable/ic_photo_camera"
                    fab:fab_size="mini"
                    />
            </com.getbase.floatingactionbutton.FloatingActionsMenu>

Screenshot

Scroll or multiple lines for FloatingActionButton

Suppose you want to add 10 FloatingActionButtons in the screen, some of them will not be shown, it would be nice to be able to scroll the FloatingActionButtons when the FloatingActionMenu is expanded, or set a grid of how the FloatingActionButton are positioned, like 4 lines of buttons.
Thanks

Custom background drawable

Can you add the option to set background drawable?
It can be useful when you need to disable the button, with current state it just has 'colorNormal'.

cant work with floating menu

How to implement floating menu correctly. Sometimes,, when I add view, it never expands by clicking. onClickListener doesnt work.
Sometimes when it works, it align itself so as to fit the view that i added. I have arranged button at parent right by default. I comes to somewhere around center. i tried adding direction to view from right to left, but with no success.

java.lang.OutOfMemoryError

I'm using version 1.10 right now. I noticed there are some OutOfMemoryError on crashlytics for some time.
I checked the release notes, It seems it wasn't fixed yet. So I post an issue here.

I thinks this is the same problem from this issue:
alexvasilkov/FoldableLayout#10

Here is the trace:
Caused by: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Bitmap.java)
at android.graphics.Bitmap.createBitmap(Bitmap.java:929)
at android.graphics.Bitmap.createBitmap(Bitmap.java:902)
at android.graphics.Bitmap.createBitmap(Bitmap.java:869)
at com.getbase.floatingactionbutton.FloatingActionButton.createStrokesDrawable(FloatingActionButton.java:164)
at com.getbase.floatingactionbutton.FloatingActionButton.updateBackground(FloatingActionButton.java:112)
at com.getbase.floatingactionbutton.FloatingActionButton.init(FloatingActionButton.java:75)
at com.getbase.floatingactionbutton.FloatingActionButton.(FloatingActionButton.java:53)

Change states

Change FAB state when click.

Allow icon to animate, like AddFAB to change into loading, etc.

Enable 'enabled' state

Conflict with AppCompat

When i add this library to my project, i got an aapt error.
"Error:Attribute "icon" has already been defined"
This is only if i use AppCompat.

FloatingActionButton.SIZE_MINI ???

Sample code issue?

  FloatingActionButton button = (FloatingActionButton) findViewById(R.id.setter);
  button.setSize(FloatingActionButton.SIZE_MINI);

Android Studio complains that button.setSize value must be 0 or 1
Help?

TextView + FloatingActionButton

I'm trying to put a TextView next to a FloatingActionButton. But the width of FloatingActionMenu not allows it to fit the two, using match_parent or by setting in hand widh also is not working. Any suggestions for how I can do this?

Exemple:

 <com.getbase.floatingactionbutton.FloatingActionsMenu
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginTop="16dp"
        app:fab_addButtonColorNormal="@color/white"
        app:fab_addButtonColorPressed="@color/primary_button_pressed_color"
        app:fab_addButtonPlusIconColor="?attr/colorPrimary">


        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:layout_marginEnd="50dp"
                android:layout_marginRight="50dp"
                android:text="Teste" />

            <com.getbase.floatingactionbutton.FloatingActionButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                app:fab_colorNormal="@color/white"
                app:fab_colorPressed="@color/primary_button_pressed_color"
                app:fab_size="mini" />

        </FrameLayout>


        <com.getbase.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_colorNormal="@color/white"
            app:fab_colorPressed="@color/primary_button_pressed_color"
            app:fab_size="mini" />

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_colorNormal="@color/white"
            app:fab_colorPressed="@color/primary_button_pressed_color"
            app:fab_size="mini" />

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/floating_action_button_diary_my_items_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_colorNormal="@color/white"
            app:fab_colorPressed="@color/primary_button_pressed_color"
            app:fab_size="mini" />

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_colorNormal="@color/white"
            app:fab_colorPressed="@color/primary_button_pressed_color"
            app:fab_size="mini" />


    </com.getbase.floatingactionbutton.FloatingActionsMenu>

'White glow' on top-side of FAB.

I've noticed a 'white glow' on the top side of the FAB (See attached).

I'm not exactly sure what the createStrokesDrawable method does (drawable stuff isn't my forte), but I was trying to work out what was causing the 'white glow', and sure enough, out-commenting the following fixed it:

    // inner top
    paint.setShader(new LinearGradient(innerStrokeRect.centerX(), innerStrokeRect.top, innerStrokeRect.centerX(), innerStrokeRect.bottom,
            new int[]{Color.WHITE, HALF_TRANSPARENT_WHITE, Color.TRANSPARENT},
            new float[]{0f, 0.2f, 1f},
            TileMode.CLAMP
    ));

In my opinion, removing the 'inner top' stroke would be an enhancement.

So, on the left is the standard, untouched FAB. On the right is the FAB generated with the 'inner top' commented out.

Comparison

FloatingActionsMenu's expand orientation

It would be a nice feature if you allow us to set the orientation of FloatingActionsMenu to other directions; as of now its child would always expand upward.

Cannot set typeface to floatingActionButton view

Unable to set typeface to floatingActionButton view. I am trying to use fontawesome icons for each floatingActionButton. For now, i am using app:fab_icon to set the icon from the drawables folder. But, would like use fontAwesome Icons. Please show me a way.

background shadow

When the floating menu is opened, Is it possible to show the background shadow to disable background click event like inbox?

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.