Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.s1lenced:floatingactionbuttonspeeddial:-SNAPSHOT'
}
dependencies {
implementation("com.github.s1lenced:floatingactionbuttonspeeddial:-SNAPSHOT")
}
<dependency>
<groupId>com.github.s1lenced</groupId>
<artifactId>floatingactionbuttonspeeddial</artifactId>
<version>-SNAPSHOT</version>
</dependency>
libraryDependencies += "com.github.s1lenced" % "floatingactionbuttonspeeddial" % "-SNAPSHOT"
:dependencies [[com.github.s1lenced/floatingactionbuttonspeeddial "-SNAPSHOT"]]
Android library providing an implementation of the Material Design Floating Action Button Speed Dial.
RecyclerView
and NestedScrollView
behaviorCheck the Waffle.io board.
The library is available on Jcenter so no additonal repository is required.
Dependencies entry (latest version on Jcenter ):
implementation "com.leinardi.android:speed-dial:1.0-alpha05"
You can use JitPack to test the latest master
(remember that master
is the development branch and can be unstable or completely broken).
Add the JitPack repository to your build file:
maven { url 'https://jitpack.io' }
Add the dependency
implementation 'com.github.leinardi:FloatingActionButtonSpeedDial:master-SNAPSHOT'
SpeedDialView
Add the SpeedDialView
to your layout:
<com.leinardi.android.speeddial.SpeedDialView
android:id="@+id/speedDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:sdMainFabOpenSrc="@drawable/ic_add_white_24dp" />
Add the items to the SpeedDialView
:
SpeedDialView speedDialView = findViewById(R.id.speedDial);
speedDialView.addActionItem(
new SpeedDialActionItem.Builder(R.id.fab_link, R.drawable.ic_link_white_24dp)
.create()
);
If the color customization is not requested, it is also possible to inflate the Action items form a Menu Resource:
speedDialView.inflate(R.menu.menu_speed_dial);
Only the attributes android:id
, android:icon
and android:title
are supported.
Add the click listeners:
speedDialView.setOnActionSelectedListener(new SpeedDialView.OnActionSelectedListener() {
@Override
public boolean onActionSelected(SpeedDialActionItem speedDialActionItem) {
switch (speedDialActionItem.getId()) {
case R.id.fab_link:
showToast("Link action clicked!");
return false; // true to keep the Speed Dial open
default:
return false;
}
}
});
speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() {
@Override
public void onMainActionSelected() {
// Call your main action here
return false; // true to keep the Speed Dial open
}
@Override
public void onToggleChanged(boolean isOpen) {
Log.d(TAG, "Speed dial toggle state changed. Open = " + isOpen);
}
});
The SpeedDialActionItem.Builder
provides several setters to customize the aspect of one item:
mSpeedDialView.addActionItem(
new SpeedDialActionItem.Builder(R.id.fab_custom_color, R.drawable.ic_custom_color)
.setFabBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.material_white_1000, getTheme()))
.setFabImageTintColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme()))
.setLabel(getString(R.string.label_custom_color))
.setLabelColor(Color.WHITE)
.setLabelBackgroundColor(ResourcesCompat.getColor(getResources(), R.color.inbox_primary, getTheme()))
.setLabelClickable(false)
.create()
);
Is is also possible to specify a theme to easily change the FAB background and ripple effect color:
mSpeedDialView.addActionItem(
new SpeedDialActionItem.Builder(R.id.fab_custom_theme, R.drawable.ic_theme_white_24dp)
.setLabel(getString(R.string.label_custom_theme))
.setTheme(R.style.AppTheme_Purple)
.create());
<style name="AppTheme.Purple" parent="AppTheme">
<item name="colorPrimary">@color/material_purple_500</item>
<item name="colorPrimaryDark">@color/material_purple_700</item>
<item name="colorAccent">@color/material_purple_a700</item>
<item name="colorControlHighlight">@color/material_purple_200</item>
</style>
You simply need to add the SpeedDialOverlayLayout
to your layout:
<com.leinardi.android.speeddial.SpeedDialOverlayLayout
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
and then provide the instance of that layout to the SpeedDialView
:
SpeedDialOverlayLayout overlayLayout = findViewById(R.id.overlay);
mSpeedDialView.setSpeedDialOverlayLayout(overlayLayout);
RecyclerView
or a NestedScrollView
Just apply the ScrollingViewSnackbarBehavior
to the SpeedDialView
. This can be done via XML using
the convenience string resource @string/speeddial_scrolling_view_snackbar_behavior
:
<com.leinardi.android.speeddial.SpeedDialView
android:id="@+id/speedDial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behavior="@string/speeddial_scrolling_view_snackbar_behavior" />
Or programmatically:
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) speedDialView.getLayoutParams();
params.setBehavior(new SpeedDialView.ScrollingViewSnackbarBehavior());
speedDialView.requestLayout();
NB: for the behaviors to work, SpeedDialView
needs to be a direct child of CoordinatorLayout
SnackbarBehavior
Since the SnackbarBehavior
is enabled by default and, afaik, it is not possible to remove a Behavior, simply use apply the SpeedDialView.NoBehavior
instead:
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) speedDialView.getLayoutParams();
params.setBehavior(new SpeedDialView.NoBehavior());
speedDialView.requestLayout();
A fully working example is available here.
https://www.youtube.com/watch?v=tWowiF5ElAg
<img src="/art/screenshot_api_27.png" width="215"/> <img src="/art/screenshot_api_16.png" width="215"/> <img src="/art/screenshot_api_27_top_fab_bottom_expansion.png" width="215"/> <img src="/art/screenshot_api_27_bottom_fab_left_expansion.png" width="215"/>
SpeedDialActionItem.Builder
?It can be done in XML using the <item type="id" />
:
<resources>
<item name="fab_action1" type="id" />
<item name="fab_action2" type="id" />
<item name="fab_action3" type="id" />
<item name="fab_action4" type="id" />
</resources>
You can set a different value for the max length of the label overriding sd_label_max_width
:
<dimen name="sd_label_max_width">240dp</dimen>
More info here.
The color of the SpeedDialOverlayLayout
can be changed simply using the android:background
attribute or, programmatically, using the equivalent setter like any other view.
Toolbar
inside a CoordinatorLayout
?It can be done using the attribute app:layout_behavior="@string/appbar_scrolling_view_behavior"
:
<com.leinardi.android.speeddial.SpeedDialOverlayLayout
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
See the CHANGELOG.md
This project is based on floating-action-menu by ArthurGhazaryan.
Copyright 2018 Roberto Leinardi.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.