0

i have chip group in xml layout and need to add chip dynamically. i need to add theme dynamically ,without changing the app theme i want to set material theme for chip view till now i cant find a proper solution , i will show my code snippet. i need your help badly

Chip chip = new Chip(mContext);
        chip.setCloseIconVisible(true);
        chip.setText(dataOptions.getListTitle());
        chip.setTextAppearance(mContext, R.style.button_style_value_color_black);
        chip.setHeight(30);
        chip.isCloseIconVisible();
        chip.setChipStrokeColorResource(R.color.chip_stroke_color);
        chip.setChipStrokeWidth(1f);
        chip.setCloseIconTintResource(R.color.grey_500);
        chip.setChipBackgroundColorResource(R.color.chip_background);
        chip.setChipCornerRadius(10f);
        mBinding.feNotesChip.addView(chip);

   chip.setOnCloseIconClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mAdapter.setItemToTheList(dataOptions, mBinding.feNotesEt.getText());
                mBinding.feNotesChip.removeView(chip);
                dataOptionsList.remove(dataOptions);
                saveToFormElement(dataOptionsList, newList);
            }
        });
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
jins joseph
  • 271
  • 1
  • 11
  • 1
    Use this [constructor](https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/chip/Chip.java#L189) and pass in the `style` – denvercoder9 Sep 19 '19 at 08:01
  • 1
    @sonnet the 3rd parameter is **not** a style. It is just the attribute in the app theme. – Gabriele Mariotti Dec 18 '19 at 15:09

1 Answers1

0

Using this library (https://github.com/Plumillon/ChipView) You can extend from their Adapter (i.e., ChipViewAdapter) and override the methods needed, I used to change backgrounds on specific conditions

    @Override
    public int getBackgroundRes(int position) {
        if (chipList.get(position).getChipType().equalsIgnoreCase(AppConstants.LOCATION)) {
            return drawable1;
        }
        return drawable2;
    }
Ryan M
  • 18,333
  • 31
  • 67
  • 74
h_malik
  • 167
  • 1
  • 8