package com.dollearn.student.views
|
|
import android.annotation.SuppressLint
|
import android.app.Activity
|
import android.content.Context
|
import android.graphics.Color
|
import android.util.AttributeSet
|
import android.view.LayoutInflater
|
import android.view.View
|
import android.widget.FrameLayout
|
import android.widget.TextView
|
import com.dollearn.student.R
|
import com.umeng.social.tool.ComposeTool.textColor
|
import org.jetbrains.anko.textColor
|
|
|
@SuppressLint("CustomViewStyleable")
|
class FormView(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
|
lateinit var rootview: View
|
private val title by lazy {
|
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.form_view)
|
val title = typedArray.getString(R.styleable.form_view_title)
|
typedArray.recycle()
|
title
|
}
|
private val info by lazy {
|
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.form_view)
|
val info = typedArray.getString(R.styleable.form_view_info)
|
typedArray.recycle()
|
info
|
}
|
private val infoColor by lazy {
|
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.form_view)
|
val infoColor = typedArray.getString(R.styleable.form_view_infoColor)
|
typedArray.recycle()
|
infoColor
|
|
}
|
|
init {
|
init()
|
}
|
|
|
lateinit var infoView: TextView
|
|
fun setInfo(s: String) {
|
infoView.text = s
|
}
|
fun setInfoColor(s: Int) {
|
infoView.textColor = s
|
}
|
fun init() {
|
|
rootview = LayoutInflater.from(context).inflate(R.layout.form_view_layout, this, true)
|
rootview.findViewById<TextView>(R.id.title).text = title
|
infoView = rootview.findViewById<TextView>(R.id.info).apply {
|
text = info
|
textColor = Color.parseColor(infoColor ?: "#333333")
|
}
|
}
|
|
}
|