Coder Social home page Coder Social logo

kojofosu / splitbutton Goto Github PK

View Code? Open in Web Editor NEW
118.0 1.0 10.0 150 KB

A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

License: Apache License 2.0

Kotlin 100.00%
menu action button split hactoberfest hactoberfest2021 hacktoberfest hacktoberfest2021 android kotlin

splitbutton's Introduction

SplitButton

Jit

A dual-function menu button that offers a default action as well as the possibility of choosing a different action by selecting from a set of alternatives.

Setup

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        //...omitted for brevity
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

dependencies {
   implementation "com.github.kojofosu:SplitButton:$latest_release"
}

๐Ÿ’ก Tech Used

Demo

demodemo

Usage

Sample implementation here

Split Button

  • Add SplitButton to your xml layout.
    <com.mcdev.splitbuttonlibrary.SplitButton
        android:id="@+id/split_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

Initialize and customise split button

    var splitBtn: SplitButton = findViewById(R.id.split_btn)
    
    splitBtn.setTextColor(R.color.black)
    splitBtn.setIconColor(android.R.color.white)
    splitBtn.setBgColor(android.R.color.holo_orange_light)
    splitBtn.setMenuItems(R.menu.split_menu)
    splitBtn.itemColor = android.R.color.holo_blue_dark // set menu items color

Button listener

            splitBtn.setOnButtonClickListener(object : OnButtonClickListener {
                override fun onClick(itemId: Int, itemTitle: String?) {
                    Log.d("TAG", "onClick: id :$itemId")
                    Log.d("TAG", "onClick: title :$itemTitle")
                    if (itemId == R.id.send) {

                        Toast.makeText(this@MainActivity, "Send", Toast.LENGTH_SHORT).show()
                        Log.d("TAG", "onClick: send  ")
                    }else if (itemId == R.id.sfl) {

                        Toast.makeText(this@MainActivity, "Save for later", Toast.LENGTH_SHORT).show()
                        Log.d("TAG", "onClick: bookmark ")
                    } else if (itemId == R.id.draft) {
                        Toast.makeText(this@MainActivity, "Draft", Toast.LENGTH_SHORT).show()
                    }
                }
            })

Add menu items. You can set your items in arraylist

       setMenuItems(
           listOf(
               SplitMenu(0, "Merge", R.drawable.ic_merge_git_icon),
               SplitMenu(1, "Rebase", R.drawable.git_request_icon)
           )
       )

Add menu items. You can also create menu list and place it in src/main/res/menu/ directory.

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@+id/send"
            android:icon="@drawable/ic_paper_plane"
            android:title="Send"/>
    
        <item
            android:id="@+id/sfl"
            android:icon="@drawable/ic_calendar"
            android:title="Schedule"/>
    
        <item
            android:id="@+id/draft"
            android:icon="@drawable/ic_bookmark"
            android:title="Draft"/>
    </menu>

Style menu items

  • To style menu items to change background color etc
    <style name="PopMen" parent="Widget.AppCompat.PopupMenu.Overflow">
        <!-- change menu text color-->
        <item name="android:textColor">@android:color/black</item> 
        <!--change popup menu background color-->
        <item name="popupMenuBackground">@android:color/holo_orange_light</item>

        <item name="android:radius">30dp</item>
        <item name="cardCornerRadius">30dp</item>
        <item name="cornerRadius">30dp</item>
    </style>

Licensed under the Apache-2.0 License

splitbutton's People

Contributors

kojofosu avatar suyalamritanshu avatar xtanion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

splitbutton's Issues

Documentation

Hi,
there is i believe outdated documentation

  1. splitBtn.setMenuItems(R.menu.split_menu)
    shoukd be
    splitBtn.setMenuItems(R.menu.split_menu, style)

  2. splitBtn.itemColor = android.R.color.holo_blue_dark
    shoukd be .setItemColor(color)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.