Create Round Floating ActionMenu in Android.

Here I going to teach you how to use floating action button in your android application . this will help you to build rich GUI Menu in your application. Actually we have two ways to do  .one is create a  Floatlayout then write code your self .this is a hard way to create flating round menu .here I am going to teach you very simple and easy way to do.

we have lots of library in github to do this. following is the one which we are going to create in our application 
Float Menu

for Create this menu your API level should be greater  than 15 (API >= 15) 

now we start to create this ,menu by following steps

  • Add following dependencies in your Gradle Scripts >    build.gradle(Module:app)  then  Press the Sync button 

 dependencies {
    compile ‘com.oguzdev:CircularFloatingActionMenu:1.0.2’
}

this library automatically download by your android studio after add this dependencies your code will be look like this

apply plugin: ‘com.android.application’
android {
    compileSdkVersion 23
    buildToolsVersion “23.0.0”
    defaultConfig {
        applicationId “com.example.dhanish.orderfood”
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName “1.0”
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’
        }
    }
}
dependencies {
    compile fileTree(include: [‘*.jar’], dir: ‘libs’)

    compile ‘com.oguzdev:CircularFloatingActionMenu:1.0.2’
}

  • Create a image view object in your MainActivity .then set a icon for image view


ImageView icon = new ImageView(this);
icon.setImageResource(R.drawable.cart);

r.drawable.cart this is a image location and name .which i created before then coped to drawable folder

then copy the following code

FloatingActionButton actionButton = new FloatingActionButton.Builder(this)
                                        .setContentView(icon)
                                        .build();

this is to create a main menu .

check now your code will be look like following.

        ImageView icon = new ImageView(this); // Create an icon        icon.setImageResource(R.drawable.cart);
        FloatingActionButton actionButton = new FloatingActionButton.Builder(this)                .setContentView(icon)                .build();

now run your application ta-da you can see the round main menu in bottom left of your main activity

to create the sub menus like above you have to copy following code

SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this);
// repeat many times:
ImageView itemIcon = new ImageView(this);
itemIcon.setImageDrawable(r.id.subicon);
SubActionButton button1 = itemBuilder.setContentView(itemIcon).build();
FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this)
                                    .addSubActionView(button1)
                                   .attachTo(actionButton)
                                    .build();

Reply

five × 4 =