Reputation: 2448
There are lots of custom libraries for achieving the FAB menu thing. But I want it to be done without using any custom libraries. I want to achieve this FAB Menu natively.
Please don't suggest me any custom library
Upvotes: 15
Views: 29179
Reputation: 638
You could do this natively using visibility... Each press on the FAB (ImageView) will toggle visibility with an animation.
I won't write a working sample code, but this should be enough info to help implement a custom floating action button in this way.
XML
android:onClick="fabMainClicked"
JAVA
public void fabMainClicked(View view)
{
ImageView fabDrop1 = (ImageView) findViewById(R.id.fabDrop1);
ImageView fabDrop2 = (ImageView) findViewById(R.id.fabDrop2);
if (fabDrop1.getVisibility() == fabDrop1.GONE)
{
fabDrop1.setVisibility(fabDrop1.VISIBLE);
fabDrop2.setVisibility(fabDrop2.VISIBLE);
}
}
Each ImageView will need to be animated via a custom animator to slide up or onto the screen.
Each ImageView will use a res/drawable as the background to provide a circle and a res/drawable for the center image.
Scale type should be set to center.
Good luck.
Upvotes: 0
Reputation: 304
add this dependency to the app build.gradle
compile 'com.android.support:design:23.1.0'
compile 'com.github.clans:fab:1.6.2'
Add follow the below link Floating Action Menu
Upvotes: 0
Reputation: 7390
You can go for android's design library. add this gradle in to your build file
compile 'com.android.support:design:23.0.1'
and follow this link, which is a stackoverflow link tells how to use. and this is the link of an sample app.
Example :
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/ic_done"
app:layout_anchor="@id/viewA"
app:layout_anchorGravity="bottom|right|end"/>
you can create multiple fab and play with its visibility
UPDATE
I think you have to use third party library to do this. please go through this library, this might help you
Upvotes: 3