【发布时间】:2019-03-05 11:27:57
【问题描述】:
我正在使用 android.support.design.chip.Chip,我遇到的问题是,当我通过 setText("...") 动态设置文本时>,文本通过重叠图标错误地显示,但是当我在 xml 文件中将其设置为 app:chipText="Hello" 时,它显示正确。
这里有我的代码:
activity.java:
Chip x= new Chip(mView);
x.setChipDrawable(ChipDrawable.createFromResource(mView, R.xml.chip_style));
chip_style.xml:
<?xml version="1.0" encoding="utf-8"?>
<chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.MaterialComponents.Chip"
app:chipIcon="@drawable/ic_person"/>
---------解决方案----------
那么,解决方案就是使用Chip方法setChipText(CharSequence text)
【问题讨论】:
标签: android android-widget settext android-chips