我创建了一个实时Firebase数据库,其子级之一是“可用性”。在列表视图中填充所有Firebase数据时,如果“ availability”的字符串值为“ yes”,则我希望子级的文本用绿色着色,否则用红色着色。 可能吗?如果是,请给我指路。 (我在各种各样的活动中都给孩子装了药,如果我能普遍地陈述这种情况,那将真的很有帮助) 谢谢。
答案 0 :(得分:2)
可以在下课时使用 您必须像这样创建自定义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);
}
}
}