罗明文
22 小时以前 442124baa483f8d1c4aaca7ff81e15dd3f122363
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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")
        }
    }
 
}