-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Floating Action Button SDK
First of all, the most basic source is found from another library but it has been done so many works and this library has becoming irrelevant.
There are few FAB buttons we can use
-
One piece of half transparent button com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.JellyBeanFloatingActionButton mainly comes with the transparent background
-
Material FAB as One Solid button also found in FloatingActionsMenu
-
Material FAB Menu. See the sample configuration and it also documented in a separated xml file com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.FloatingActionsMenu. Please also refer to FloatingActionsMenu
##Example for JellyBeanFloatingActionButton
<com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.JellyBeanFloatingActionButton
android:id="@+id/custom_urv_add_floating_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
app:icon="@mipmap/ic_filter_v2"
app:urv_fab_alphaPressed="0.93"
app:urv_fab_alphaNormal="0.93"
app:urv_fab_colorNormal="@color/main_fab_background"
app:urv_fab_colorPressed="@color/main_fab_press_background" />
##Showing and hiding toolbar and floating button:
ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
}
@Override
public void onDownMotionEvent() {
}
@Override
public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
if (observableScrollState == ObservableScrollState.DOWN) {
ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView,getScreenHeight());
} else if (observableScrollState == ObservableScrollState.UP) {
ultimateRecyclerView.hideToolbar(toolbar,ultimateRecyclerView,getScreenHeight());
} else if (observableScrollState == ObservableScrollState.STOP) {
}
}
});
As the result, you will able to get something like this:
To create my own FloatingActionsMenu, but there's no way to set it to recycler view. The only method is setDefaultFloatingActionButton, but it is for one button. This method is commented out in library code:
public void setCustomFloatingActionView(View customFloatingActionView) {
this.floatingActionMenu = floatingActionMenu;
}
###Edit the layout file:
app:recyclerviewFloatingActionView="@layout/custom_fab_view"
The detail in the xml:
<com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.FloatingActionsMenu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/customfloatingActionMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:addButtonColorNormal="#ffffff"
fab:addButtonColorPressed="#f1f1f1"
fab:addButtonPlusIconColor="#808080"
fab:urv_fab_colorPressed="#f1f1f1"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="15dp"
android:layout_marginBottom="15dp"
android:visibility="gone">
<com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.AddFloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|bottom"
fab:plusIconColor="#808080"
fab:urv_fab_colorNormal="#ffffff" />
<com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:icon="@drawable/urv_floating_action_button_ic_fab_star"
fab:urv_fab_colorNormal="#ff5f9a"
fab:urv_fab_colorPressed="#ec407a" />
</com.marshalchen.ultimaterecyclerview.ui.floatingactionbutton.FloatingActionsMenu>
###To make it to be enabled on the floating action menu
FloatingActionsMenu floatMenu = (FloatingActionsMenu) ultimateRecyclerView.getCustomFloatingActionView();
for (int i = 0; i < floatMenu.getChildCount(); i++) {
FloatingActionButton button = (FloatingActionButton) floatMenu.getChildAt(i);
switch (button.getId()) {
case R.id.buttonOne:
button.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "ONE PRESSED", Toast.LENGTH_SHORT).show();
}
});
break;
case R.id.buttonTwo:
button.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "TWO PRESSED", Toast.LENGTH_SHORT).show();
}
});
break;
case R.id.buttonThree:
button.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "THREE PRESSED", Toast.LENGTH_SHORT).show();
}
});
break;
default:
break;
}
}