All Projects → sourin00 → MaterialChipsInputDemo

sourin00 / MaterialChipsInputDemo

Licence: MIT license
Using the new material library from google to implement Chips just like the Gmail app. Using commas to generate new chips from EditText inside ChipGroup and deleting them on close icon click or backspace press from soft keypad.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to MaterialChipsInputDemo

Biometric-Authentication-Android
A sample implementation of AndroidX biometrics API using Kotlin. Authenticate using biometrics or PIN/Password if biometrics isn't available on device. Fully implemented in Jetpack compose using Material 3 dynamic theming and also has a separate implementation in xml with MDC 3.
Stars: ✭ 29 (+93.33%)
Mutual labels:  androidx
svelte-material
Modular and customizable Material Design UI components for Svelte.js
Stars: ✭ 30 (+100%)
Mutual labels:  material-components
personal-website
Personal website – made with Next.js, Preact, MDX, RMWC, & Vercel
Stars: ✭ 16 (+6.67%)
Mutual labels:  material-components
hat-view
Allow to put "hat" on TextView. Inspired by Telegram appbar title with Santa Claus hat 🎅🏻
Stars: ✭ 51 (+240%)
Mutual labels:  androidx
material-components-flutter-motion-codelab
Codelab for Material motion for Flutter
Stars: ✭ 32 (+113.33%)
Mutual labels:  material-components
ShaderShowcaseApp
A Jetpack Compose-based app to exhibit all the beautiful GLSL Fragment shaders I have ever written, where you can set them as Live Wallpaper.
Stars: ✭ 173 (+1053.33%)
Mutual labels:  androidx
django material widgets
Django widgets styled with Material Components for the Web
Stars: ✭ 24 (+60%)
Mutual labels:  material-components
AsyncChain
异步链式库,类似RXJava,可以用于切换主线程,或者执行一串相互依赖的任务
Stars: ✭ 17 (+13.33%)
Mutual labels:  androidx
Dads
*BA DUM TSSS*
Stars: ✭ 240 (+1500%)
Mutual labels:  androidx
media-picker
Easy customizable picker for all your needs in Android application
Stars: ✭ 167 (+1013.33%)
Mutual labels:  material-components
bye-bye-jetifier
Gradle Plugin to verify if you can keep Android Jetifier disabled
Stars: ✭ 173 (+1053.33%)
Mutual labels:  androidx
material-design-spinner
Material design spinner for apps powered by Starling and Feathers
Stars: ✭ 23 (+53.33%)
Mutual labels:  material-components
NavigationComponentPlayground
Sample app leveraging Android Navigation Component
Stars: ✭ 60 (+300%)
Mutual labels:  androidx
RePluginX
🔥 Supports AndroidX and Android-Support
Stars: ✭ 32 (+113.33%)
Mutual labels:  androidx
aurelia-mdc-web
Aurelia wrapper for Material Design (Web) Components
Stars: ✭ 43 (+186.67%)
Mutual labels:  material-components
preact-mdc
material design components for preact using material-components-web sass styles (for live demo click the link below)
Stars: ✭ 23 (+53.33%)
Mutual labels:  material-components
material
🎨 Materialize your forum with this Flarum extension that uses the latest guidelines.
Stars: ✭ 14 (-6.67%)
Mutual labels:  material-components
WanAndroidJetpack
🔥 WanAndroid 客户端,Kotlin + MVVM + Jetpack + Retrofit + Glide。基于 MVVM 架构,用 Jetpack 实现,网络采用 Kotlin 的协程和 Retrofit 配合使用!精美的 UI,便捷突出的功能实现,欢迎下载体验!
Stars: ✭ 124 (+726.67%)
Mutual labels:  androidx
aurelia-mdc-bridge
Aurelia Mdc Bridge is a collection of wrappers for Material Design Components.
Stars: ✭ 19 (+26.67%)
Mutual labels:  material-components
web
Web interface for Cayley
Stars: ✭ 24 (+60%)
Mutual labels:  material-components

MaterialChipsInputDemo

Using the new material library from google to implement Chips just like the Gmail app. Using commas to generate new chips from EditText inside ChipGroup and deleting them on close icon click or backspace press from soft keypad.

Getting Started

Use this if you want to implement material chips without any 3rd party library dependency just using EditText, Chip, ChipGroup, HorizontalScrollView

Prerequisites

Must have SDK 28 included in dependency either support library or androidX and material. I have used androidX and material

compileSdkVersion 28

implementation 'com.google.android.material:material:1.0.0-rc01'

Implementation

Layout code

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:hint="@string/enter_chip_txt"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <!--Horizontal ScrollView to accomodate chips overflow by making them scroll-->

        <HorizontalScrollView
            android:id="@+id/horizontal_scroll_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:layout_editor_absoluteX="8dp"
                tools:layout_editor_absoluteY="503dp">

                <!--ChipGroup to hold multiple chips and help in removal by getting child elements-->

                <com.google.android.material.chip.ChipGroup
                    android:id="@+id/chipGroup"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintBottom_toBottomOf="@+id/textInputEditText"
                    app:layout_constraintEnd_toStartOf="@+id/textInputEditText"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/textInputEditText" />

                <!--Entering chip generation text and using commas to detect when a new chip is to be generated-->

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/textInputEditText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:hint="@string/enter_chip_txt"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toEndOf="@+id/chipGroup"
                    app:layout_constraintTop_toTopOf="parent" />

            </androidx.constraintlayout.widget.ConstraintLayout>

        </HorizontalScrollView>
    </com.google.android.material.textfield.TextInputLayout>
    

TextWatcher for adding chips on enter comma

override fun afterTextChanged(s: Editable?) {
                val trimmed = s.toString().trim { it <= ' ' }
                if (trimmed.length > 1 && trimmed.endsWith(",")) {
                    val chip = Chip(this@MainActivity)
                    chip.text = trimmed.substring(0, trimmed.length - 1)
                    chip.isCloseIconVisible = true
                    
                    //Callback fired when chip close icon is clicked 
                    chip.setOnCloseIconClickListener {
                        chipGroup.removeView(chip)
                    }
                    
                    chipGroup.addView(chip)
                    s?.clear()
                }
            }
            

Deletion on backspace press

textInputEditText.setOnKeyListener { _, _, event ->
            if (event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_DEL) {
                if (textInputEditText.length() == 0 && chipGroup.childCount > 0) {
                    val chip = chipGroup.getChildAt(chipGroup.childCount - 1) as Chip
                    chipGroup.removeView(chip)
                }
            }
            false
        }

Reference

Material Chips

Authors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].