Giter Site home page Giter Site logo

robertlevonyan / material-chip-view Goto Github PK

View Code? Open in Web Editor NEW
1.4K 24.0 153.0 1.24 MB

Material Chip view. Can be used as tags for categories, contacts or creating text clouds

Kotlin 100.00%
android android-library android-development api chip view text tags tag material-chip

material-chip-view's Introduction

Material Chip View

Material Chip view. Can be used as tags for categories, contacts or creating text clouds. This library can be an alternative for Material Chip from Jetpack library.
Android Arsenal Android Arsenal API
MaterialChipVersion Maven Central
ComposeChipVersion Maven Central
Material3ComposeChipVersion Maven Central

Setup

Add following line of code to your project level gradle file

  repositories {
    mavenCentral()
  }

Add following line of code to your module(app) level gradle file

Groovy:

    implementation 'com.robertlevonyan.view:MaterialChipView:<MaterialChipVersion>'

Kotlin:

    implementation("com.robertlevonyan.view:MaterialChipView:$MaterialChipVersion")

Maven:

  <dependency>
    <groupId>com.robertlevonyan.view</groupId>
    <artifactId>MaterialChipView</artifactId>
    <version>MaterialChipVersion</version>
    <type>pom</type>
  </dependency>

For Jetpack Compose version

    implementation("com.robertlevonyan.compose:materialchip:$ComposeChipVersion")

or if you want to yse Material3 version

    implementation("com.robertlevonyan.compose:material3chip:$Material3ComposeChipVersion")

Usage

  <com.robertlevonyan.views.chip.Chip
    android:id="@+id/chip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/customTitle" />

alt text

Cutomizing Chip

    app:mcv_closable="true"

alt text

    app:mcv_selectable="true"
alt text alt text
    app:mcv_chipIcon="@drawable/customIcon"

alt text

    app:mcv_backgroundColor="@color/customChipBackgroundColor"
    app:mcv_closeColor="@color/customCloseIconColor"
    app:mcv_selectedBackgroundColor="@color/customSelectedChipColor"
    app:mcv_textColor="@color/customTitleColor"
alt text alt text

Attributes

Custom Atributes Description
app:mcv_textColor Custom color for text label
app:mcv_backgroundColor Custom background color
app:mcv_selectedBackgroundColor Custom background color when selected
app:mcv_chipIcon Icon resource for Chip
app:mcv_closable Chip with close button
app:mcv_closeColor Custom color for close button
app:mcv_selectable Chip with selection button
app:mcv_selectedTextColor Custom color for label when selected
app:mcv_cornerRadius Change the corner radius of your Chip
app:mcv_strokeSize Add stroke to your Chip
app:mcv_strokeColor Choose a custom stroke color for your Chip
app:mcv_selectedStrokeSize Stroke size when selected
app:mcv_selectedStrokeColor Custom stroke color when selected
app:mcv_iconText Instead of an image create icon from String
app:mcv_iconTextColor Select a color for your String icon
app:mcv_iconTextBackgroundColor Select a background color for String icon

Setting Listeners

    val chip = findViewById(R.id.chip);

Chip click listener

    chip.setOnClickListener { view ->
         //Your action here...
    }

On Close button click listener

    chip.setOnCloseClickListener { view ->
         //Your action here...
    }

On Icon click listener

    chip.setOnIconClickListener { view ->
         //Your action here...
    }

On Select button click listener

    chip.setOnSelectClickListener { view: View, selected: Boolean ->
         //Your action here...
    }

Customizing Chip from code

        chip.text = "My awesome Chip" // Set Chip label
        chip.chipTextColor = chipTextColor // Set Chip label color
        chip.chipBackgroundColor = chipBackgroundColor //Set custom background color
        chip.chipSelectedBackgroundColor = chipSelectedBackgroundColor //Set custom background color when selected
        chip.chipIcon = myIconDrawable //Set Icon Drawable for Chip
        chip.chipIconBitmap = myIconBitmap //Set Icon Bitmap for Chip
        chip.closable = true //Set Chip has close button
        chip.chipCloseColor = chipCloseColor //Set custom color for close button
        chip.chipSelectedCloseColor = chipSelectedCloseColor //Set custom color for close button on selected state
        chip.selectable = false //Set Chip has selection button
        chip.chipSelected = true // Set Chip selected
        chip.chipSelectedTextColor = chipSelectedTextColor //Set custom color for label when selected
        chip.cornerRadius = 5 // Set corner radius of your Chip
        chip.strokeSize = 2 // Set width of stroke
        chip.strokeColor = strokeColor // Set stroke color for your Chip
        chip.selectedStrokeSize = 2 // Set width of stroke when selected
        chip.selectedStrokeColor = selectedStrokeColor // Set stroke color for your Chip when selected
        chip.setIconText(text, iconTextColor, iconTextBackgroundColor); // Set Chip icon text, text color and background color (in case of Kotlin iconTextColor and iconTextBackgroundColor have default value of 0)
        chip.chipHorizontalPadding = 10 // Set horizontal padding for chip

For Jetpack Compose version

setContent {
  Box(modifier = Modifier.fillMaxWidth()) {
    MaterialChip(
      text = "Some Text",
      chipIcon = ChipIconRes(icon = R.drawable.android), // ChipIconBitmap or ChipIconDrawable
      interaction = ChipInteraction.Closable, // Selectable, SelectableWithoutIcon or None
      strokeSize = 1.dp,
      selectedStrokeSize = 2.dp,
      strokeColor = Color.Red,
      selectedStrokeColor = Color.Blue,
      onSelectClick = { selected ->
        // your code here
      },
      onIconClick = {
        // your code here
      },
      onChipClick = {
        // your code here
      },
      onCloseClick = {
        // your code here
      }
    )
  }
}

Also there is a MaterialChipGroup available for Jetpack Compose version

setContent {
  Box(modifier = Modifier.fillMaxWidth()) {
    MaterialChipGroup(
      items = listOf("Chip1", "Chip2", "Chip3"),
      createTitle = { it }, //returns a String for the title
      initialSelectedElementIndex = 1, // default value is -1 (means nothing is selected)
      onItemSelected = { position, element ->
        // do something
      },
      // the rest is for Chip appearance
      interaction = ChipInteraction.Selectable,
      strokeSize = 1.dp,
      selectedStrokeSize = 2.dp,
      strokeColor = Color.Red,
      selectedStrokeColor = Color.Blue,
      backgroundColor = Color.Red,
      selectedBackgroundColor = Color.Blue,
    )
  }
}

Versions

1.0.0 (Material3)

Jetpack compose version with Material 3 styling

3.0.0

Jetpack Compose support added Chip Group added for JetpackCompose

2.2.1 - 2.2.7

Update to Java 11 SDK 31 ready Minor updates

2.2.0

Migration to mavenCentral

2.1.1 - 2.1.7

Minor changes, some missing parts pushed

2.1.0

New update, now it is possible to make chip selectable without selection icon

2.0.1 - 2.0.7

Minor changes, some missing parts pushed

2.0.0

New version of the library. Fully rewritten with Kotlin and AndroidX ready 🤩

1.2.1, 1.2.2

General bug fixed

1.1.3

Selection option added

1.1.2

Icon text issue fixed

1.1.1

Updated version of Material Chip View: - the attribute names are changed to escape conflicts with other libs - added new features like customizable corner radius and stroke - recreation issue fixed for post Lollipop versions

1.0.1

Recreation issues are fixed

1.0.0

First version of library

Contact

Licence

    Material Chip View©
    Copyright 2022 Robert Levonyan
    Url: https://github.com/robertlevonyan/materialChipView

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

material-chip-view's People

Contributors

jorgedls avatar limakayo avatar przybylski avatar robertlevonyan avatar yuriabgaryan 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

material-chip-view's Issues

Manifest merger failed with multiple errors

Hi,
This an awesome library. i need to implement but i'm facing this issue
Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed with multiple errors, see logs

Take random colors in a preset color list.

Is it possible to set a topic that allows the items inside to take a random color in a preset color list, or it will look better than a simple color. And it will be more convenient to set up.

for example

`

public class ChartColorTemplate {

public static final Integer[] COMMON_COLORS = {
    rgb("#FF69B4"), rgb("#9370DB"), rgb("#6495ED"), rgb("#F08080"), rgb("#FF7F50"), rgb("#FF8C00"), rgb("#90EE90"), rgb("#40E0D0"), rgb("#00CED1"),
    rgb("#00BFFF"), rgb("#7B68EE"), rgb("#BA55D3"), rgb("#EE82EE"), rgb("#FF1493"), rgb("#FF69B4"), rgb("#20B2AA"), rgb("#00EE00"),
    rgb("#7D26CD"), rgb("#90EE90"), rgb("#CD3278"), rgb("#CD4F39"), rgb("#EEC591"), rgb("#FF3E96"), rgb("#FF6EB4"), rgb("#FFBBFF")
};

public static void addColors(ArrayList<Integer> colors, Integer... colorTemplate) {
    List<Integer> list = Arrays.asList(colorTemplate);
    Collections.shuffle(list);

    colors.addAll(list);
}

}

`

No Resource Identifier Found

When I try to add the chip via xml i keep getting the error
Error:(70) No resource identifier found for attribute 'mcv_chipIcon' in package 'com.test.testertest'
here is the xml:
<com.robertlevonyan.views.chip.Chip android:id="@+id/basketball_chip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/activity_vertical_margin" app:mcv_backgroundColor="@color/colorBasketball" app:mcv_chipIcon="@drawable/basketball" app:mcv_chipText="@string/basketball" app:mcv_closeColor="@color/primaryColor" app:mcv_hasIcon="true" app:mcv_selectable="true" app:mcv_selectedBackgroundColor="@color/colorBasketballSelected" app:mcv_textColor="@color/colorBasketballSelected" />

AppTheme conflicts

I would rename your Theme to match the name of the component, to avoid conflicts with apps.

`
Error:Execution failed for task ':my-widget:processDebugAndroidTestManifest'.

Manifest merger failed : Attribute application@theme value=(@style/AppTheme.MyAppTheme) from [tested_artifact::my-widget] AndroidManifest.xml:15:9-50
is also present at [com.robertlevonyan.view:MaterialChipView:1.1.2] AndroidManifest.xml:16:9-40 value=(@style/AppTheme).
Suggestion: add 'tools:replace="android:theme"' to element at manifestMerger3134971992410343730.xml:7:5-9:19 to override.`

Selected - by click on whole chip

It sometimes can be not easy to touch exactly into selected icon on the right of the chip.
Maybe it would be useful to be able to select \ deselect chip by clicking at an entire chip.
Can't to it via Chip Click Listener because in that case if I touch it in selected icon - the behavior will merge.

selecting - Need to click chip twice

I wonder why I need to click the chip twice to finally have it selected...

Any ideas why? My Code:

channel_list_view = findViewById(R.id.channel_list);

// Add example chips
for(int i = 0; i < 30; i++) {
    Chip c = new Chip(getApplicationContext());

    c.setChipText("#channel_" + i);
    c.setSelectable(true);

    channel_list_view.addView(c);
}

Chip recycling issues

Hi there, @robertlevonyan! Thank you for that nice library.
Looks like there are some problems with Chips recycling here:
Looks like you're calling buildView() from onAttachedToWindow() which can be called multiple times in case of inner RecyclerView usage. As a result, closeIcon ImageView already exists and has a valid parent you're trying to assign.
That's also possible that typical problems are spawning with other inner views.
Thank you!

    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
        at android.view.ViewGroup.addViewInner(ViewGroup.java:4937)
        at android.view.ViewGroup.addView(ViewGroup.java:4768)
        at android.view.ViewGroup.addView(ViewGroup.java:4708)
        at android.view.ViewGroup.addView(ViewGroup.java:4681)
        at com.robertlevonyan.views.chip.Chip.initCloseIcon(Chip.java:229)
        at com.robertlevonyan.views.chip.Chip.buildView(Chip.java:113)
        at com.robertlevonyan.views.chip.Chip.onAttachedToWindow(Chip.java:97)
        at android.view.View.dispatchAttachedToWindow(View.java:17445)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3326)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3333)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:4977)
        at android.view.ViewGroup.addView(ViewGroup.java:4768)
        at android.view.ViewGroup.addView(ViewGroup.java:4708)
        at android.support.v7.widget.RecyclerView$5.addView(RecyclerView.java:778)
        at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:107)
        at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8222)
        at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8180)
        at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8168)
        at com.google.android.flexbox.FlexboxLayoutManager.layoutFlexLineMainAxisHorizontal(FlexboxLayoutManager.java:1515)
        at com.google.android.flexbox.FlexboxLayoutManager.layoutFlexLine(FlexboxLayoutManager.java:1436)
        at com.google.android.flexbox.FlexboxLayoutManager.fill(FlexboxLayoutManager.java:1288)
        at com.google.android.flexbox.FlexboxLayoutManager.onLayoutChildren(FlexboxLayoutManager.java:756)
        at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3812)
        at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3225)
        at android.view.View.measure(View.java:22071)
        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.support.design.widget.AppBarLayout.onMeasure(AppBarLayout.java:234)
        at android.view.View.measure(View.java:22071)
        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1212)
        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1552)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:141)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
2018-06-18 18:45:39.193 28712-28712/com E/AndroidRuntime:     at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6602)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at com.android.internal.policy.DecorView.onMeasure(DecorView.java:724)
        at android.view.View.measure(View.java:22071)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2422)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1504)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1761)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
        at android.view.Choreographer.doCallbacks(Choreographer.java:723)
        at android.view.Choreographer.doFrame(Choreographer.java:658)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Chip View not appearing in RecyclerView layout

Simple <com.robertlevonyan.views.chip.Chip> XML body in my recyclerview adapter layout does not show when it's inside recyclerview. It works ok in other layout that are not inside a recyclerview.

Chip need to call requestLayout for show correctly

Hi
I use chip in FlexBoxLayout that design by google and when call addView on layout, chip's appears without anything and just show empty box and need to call requestLayout to show this content

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
        @Override
        public void run() {
                chip.requestLayout();
        }
}, 250);

what's wrong?

Close icon

Chip close icon in the XML is shown as in the lib preview images, but when I compile it is displayed as a huge X icon. Could you check this please?

Rtl

Hi, does this library support rtl?

Adding a bitmap as icon has wrong scaling

I added
chipIconBitmap = getScaledBitmap(getContext(), chipIconBitmap);
and
icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
to
if (chipIconBitmap != null)
and it's perfect now. Just wanted to say that i think you overlooked the getScaledBitmap for chipIconBitmap.
Hope this helps!
P.S. Great work on this lib!

setIconText does not accept single char String

When I tried to use setIconText() with String of length 1, it throws StringIndexOutOfBoundsException. Looking up the code, it seems there's a split function to handle String whose length is more than 2 but does not consider case of length == 1:

    public static String generateText(String iconText) {
        if (iconText.length() == 2) {
            return iconText;
        }

        String[] parts = iconText.split(" ");
        if (parts.length == 1) {
            String text = parts[0];
            text = text.substring(0, 2);

            String f = text.substring(0, 1);
            String s = text.substring(1, 2);

            f = f.toUpperCase();
            s = s.toLowerCase();

            text = f.concat(s);

            return text;
        }
        String first = parts[0];
        String second = parts[1];

        first = first.substring(0, 1);
        first = first.toUpperCase();
        second = second.substring(0, 1);
        second = second.toUpperCase();

        return first.concat(second);

    }

I can't set text chip

when i set text chiptext , the chip is not modified i must click in close button to change the view .

i can add Padding

`Chip c = new Chip(getApplicationContext());
c.setChipText(AOBJ.getAuthorized_users().get(0));
c.setPadding(1,1,1,1);
c.setClosable(true);
c.changeBackgroundColor(getResources().getColor(R.color.colorAccent));

Chip b = new Chip(getApplicationContext());
b.setChipText(AOBJ.getAuthorized_users().get(0));
b.setClosable(true);
b.changeBackgroundColor(getResources().getColor(R.color.colorAccent));
b.setPadding(2,2,2,2);`

7

no matter what padding.
I´m adding the chips on a gridLayout

ChipGroup [ENHANCEMENT]

Hey there,

Cool library, but I think to make it really dynamic and usable, I think making a separate component thats ChipGroup which would make it much easier to have several of these, in a radio/multi select options

Thanks again!
Regards

Several bugs

  1. When selected the first time, the chip becomes selected then unselected suddenly.
  2. When setOnSelectClickListener in code, then chip has a weired icon(or text?)
  3. The chip can be selected only on tick icon(I think the chip can be selected by clicking all area of it makes more sense)

And for 3, I hope you can provide a method to control if the tick icon shows.
Here is the demo. Thanks for your time, I like your repo!
demo.zip

Dynamic chip set

How can i create dynamic chipset, i need to add andr remove it programmaticaly

Change chip size

Hello, I want change width and height of chip. How I can do it?

Manifest merger failed: allowBackup value=(false)

Manifest merger failed : Attribute application@allowBackup value=(false) from AndroidManifest.xml:10:9-36
  	is also present at [com.robertlevonyan.view:MaterialChipView:1.2.1] AndroidManifest.xml:12:9-35 value=(true).
  	Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at AndroidManifest.xml:8:5-85:19 to override.

when allowBackup="false" is specified in the applications manifest, this conflicts with the library.

There should be no conflict at first hand.

The inner views are created several times

What You Are Seeing?

The buildView() method is called multiple times during the initialization process, the first one by the constructor, the second in onAttachedToWindow() and finally in onSizeChanged(), creating the inner views several times.
viewshierarchy

What is Expected?

The inner views

hierarchy needs to be created only one time

What environment are you running on?

Emulator with Android 7.1.1 Google APIs

Use of chip in recyclerview

Hi, I like this library and its the best impementation of Material Chip that i've found so far. My only issue now is that i have an adapter that has a viewholder with Chip as a view in the XML.

Whenever i set the chip text using chip.setChipText(item.getCategory()); it seems that after scrolling through a few items in the view, the text on the chip starts to get jumbled and seems its overlapping with the previous values from other categories. Is there a way to ensure we clear the previous value that was set for the chip so it displays correctly as you scroll up or down the list of items in the recyclerview?

See sample below
image

Thanks.

setting setSelected(true) in OnChipClickListener

Hello, I am trying to flip the colors when a user taps on the chip. I have used setSelected(true) inside setOnChipClickListener but it's not working.

Here's my code for your reference:

Chip chip = (Chip) findViewById(R.id.chip);

 chip.setOnChipClickListener(new OnChipClickListener() {
            @Override
            public void onChipClick(View v) {
                chip.setSelected(true);
            }
 });

ps: using app:selectable in xml works but I find the checkmark is a little too small.

Use custom attributes?

Hi, I would love to use your awesome library but it's conflicting with another one already in my project:

Error:(778) Attribute "textColor" already defined with incompatible format.
Error:(586) Original attribute defined here.

Maybe using custom attr names will fix it?

Thanks in advance!

setChipIcon() does nothing

From source:

public void setChipIcon(Bitmap chipIcon) {
        this.chipIconBitmap = chipIcon;
    }

It just assigns a value to chipIconBitmap without caling buildView() which, if I am not mistaken, should take care of changes.

selectable tick icon

Hi need to have the functionality of app:mcv_selectable="true" but on the same time i dont like the tick icon . I need to hide that icon and when i click on the whole chip it should work not on tick icon. Can you suggest any solution.

Few more configurations

Will be great if you can add few more configurations of chip , such as:

  • chip corner radius
  • strore around chip with color and wight
  • chip text size

Removing and adding chips in a recycler view added multiple textviews in the chip

After Adding and removing a chip multiple times in a recyclerview, the chip ends up like this in layout inspector:
image

i have tried calling requestLayout() on multiple methods of the adapter

am i doing anything wrong in my adapter ?

here it is (without any requestLayout) :

class ZepGridAdapter(context: Context, val zepList: ObservableArrayList<String>) : RecyclerView.Adapter<ZepGridAdapter.ViewHolder>() {
 
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
        val view: View = LayoutInflater.from(parent?.context).inflate(R.layout.zep_chip, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int = zepList.size

    override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
        holder?.bind(zepList[position]) {
            zepList.removeAt(holder.adapterPosition)
        }
    }

    private val listChangedCallback = object : ObservableList.OnListChangedCallback<ObservableList<String>>() {
        override fun onChanged(p0: ObservableList<String>?) {
            notifyDataSetChanged()
        }

        override fun onItemRangeRemoved(p0: ObservableList<String>?, fromPosition: Int, itemCount: Int) {
            notifyItemRangeRemoved(fromPosition, itemCount)
        }

        override fun onItemRangeMoved(p0: ObservableList<String>?, fromPosition: Int, toPosition: Int, itemCount: Int) {
            notifyItemRangeRemoved(fromPosition, itemCount)
            notifyItemRangeInserted(toPosition, itemCount)
        }

        override fun onItemRangeInserted(p0: ObservableList<String>?, fromPosition: Int, itemCount: Int) {
            notifyItemRangeInserted(fromPosition, itemCount)
        }

        override fun onItemRangeChanged(p0: ObservableList<String>?, fromPosition: Int, itemCount: Int) {
            notifyItemRangeChanged(fromPosition, itemCount)
        }
    }

    init {
        zepList.addOnListChangedCallback(listChangedCallback)
    }

    class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {

        var chip: Chip = v.findViewById(R.id.zep_grid_chip)

        fun bind(zep: String?, onCloseClickListener: (View) -> Unit) {
            chip.chipText = zep
            chip.isClosable = true
            chip.setOnCloseClickListener {
                onCloseClickListener(chip)
            }
        }
    }
}

Chip text empty first time

First time that I show a chip, with the text set programmatically, its shown whitout text.

Every next time is shown OK.

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.