Android CircleMenu

0
830
How to use Android CircleMenu library
How to use Android CircleMenu library

TMH gives you cool Android library tutorials for development and designing also. Today library is for Menu UI named Android CircleMenu which is a simple, elegant menu with a circular layout.

Example of Android CircleMenu library
Example of Android CircleMenu library

Setup : Android CircleMenu library

Add this to your app build.gradle:

compile 'com.github.imangazalievm:circlemenu:1.0.3'

Usage

Add to your layout xml-file:

<com.imangazaliev.circlemenu.CircleMenu
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:id="@+id/circleMenu"
        >

        <com.imangazaliev.circlemenu.CircleMenuButton
            android:id="@+id/favorite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:colorNormal="#2196F3"
            app:colorPressed="#1E88E5"
            app:icon="@drawable/ic_favorite"
            />

        <com.imangazaliev.circlemenu.CircleMenuButton
            android:id="@+id/search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:colorNormal="#4CAF50"
            app:colorPressed="#43A047"
            app:icon="@drawable/ic_search"/>

        <com.imangazaliev.circlemenu.CircleMenuButton
            android:id="@+id/alert"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:colorNormal="#F44336"
            app:colorPressed="#E53935"
            app:icon="@drawable/ic_alert"/>

</com.imangazaliev.circlemenu.CircleMenu>

Set OnItemClickListener for handling menu items clicks:

CircleMenu circleMenu = (CircleMenu) findViewById(R.id.circleMenu);
circleMenu.setOnItemClickListener(new CircleMenu.OnItemClickListener() {
    @Override
    public void onItemClick(MenuButton menuButton) {

    }
});

Set OnStateUpdateListener for handling open/close actions

circleMenu.setStateUpdateListener(new CircleMenu.OnStateUpdateListener() {
    @Override
    public void onMenuExpanded() {
        
    }

    @Override
    public void onMenuCollapsed() {

    }
});

Ex code

package com.imangazaliev.circlemenu.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

import com.imangazaliev.circlemenu.CircleMenu;
import com.imangazaliev.circlemenu.CircleMenuButton;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        CircleMenu circleMenu = (CircleMenu) findViewById(R.id.circleMenu);
        circleMenu.setOnItemClickListener(new CircleMenu.OnItemClickListener() {
            @Override
            public void onItemClick(CircleMenuButton menuButton) {
                switch (menuButton.getId()) {
                    case R.id.favorite:
                        showMessage("Favorite");
                        break;
                    case R.id.search:
                        showMessage("Search");
                        break;
                    case R.id.alert:
                        showMessage("Alert");
                        break;
                    case R.id.place:
                        showMessage("Place");
                        break;
                    case R.id.edit:
                        showMessage("Edit");
                        break;
                }
            }
        });

        circleMenu.setStateUpdateListener(new CircleMenu.OnStateUpdateListener() {
            @Override
            public void onMenuExpanded() {
                Log.d("CircleMenuStatus", "Expanded");
            }

            @Override
            public void onMenuCollapsed() {
                Log.d("CircleMenuStatus", "Collapsed");
            }
        });
    }

    private void showMessage(String message) {
        Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
    }

}

Hope you like this library and please comment us with your suggestion.

Share your thoughts

Loading Facebook Comments ...
Loading Disqus Comments ...