package com.xty.common.weight

import android.content.Context
import android.graphics.Color
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.AttributeSet
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import com.xty.common.LogUtils

/**
 * 必填text
 */
class RequiredTextView(context: Context, attrs: AttributeSet?) : androidx.appcompat.widget.AppCompatTextView(context, attrs) {
    override fun setText(text: CharSequence?, type: BufferType?) {
        if (!text.isNullOrEmpty() && text.first() == '*') {
            super.setText(text, type)
        } else {
            val span = SpannableString("*$text")
            span.setSpan(ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
            super.setText(span, type)
        }
    }
}