我想为Chip设置自定义可绘制背景,就像该chip.setBackgroundDrawable(context.getResources()。getDrawable(R.drawable.bg_cutom_drawable)));一样。
但是它不起作用,它给出了一个错误
java.lang.UnsupportedOperationException: Do not set the background resource; Chip manages its own background drawable.
它需要一个chipDrawable。如何为相同的创建chipDrawable。我尝试过但无法找到解决方案。请建议我,将不胜感激。
如果要更改背景颜色,可以尝试:
ChipDrawable chipDrawable = (ChipDrawable)chip.getChipDrawable();
chipDrawable.setChipBackgroundColorResource(R.color.colorPrimary);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句