【发布时间】:2019-11-10 03:06:39
【问题描述】:
我创建了一个实时 firebase 数据库,其中一个是“可用性”。在 listview 中填充所有 firebase 数据时,如果“availability”的字符串值为“yes”,则我希望来自孩子的文本以绿色着色,否则为红色。 可能吗?如果是,请告诉我路。 (我已经在各种活动中填充了孩子,如果我能通用地说明情况将非常有帮助) 谢谢。
【问题讨论】:
我创建了一个实时 firebase 数据库,其中一个是“可用性”。在 listview 中填充所有 firebase 数据时,如果“availability”的字符串值为“yes”,则我希望来自孩子的文本以绿色着色,否则为红色。 可能吗?如果是,请告诉我路。 (我已经在各种活动中填充了孩子,如果我能通用地说明情况将非常有帮助) 谢谢。
【问题讨论】:
是的,可以在下面使用 你必须像这样创建自定义 Textview
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.TextView;
public class CustomTextViewTest extends android.support.v7.widget.AppCompatTextView {
public CustomTextViewTest(Context context) {
super(context);
}
public CustomTextViewTest(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public CustomTextViewTest(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setText(CharSequence text, BufferType type) {
super.setText(text, type);
// here set color according to text
if (text.toString().contains("availability")) {
this.setTextColor(Your Color);
} else {
this.setTextColor(Your Color);
}
}
}
【讨论】: