| | |
| | | package safeluck.drive.evaluation.customview |
| | | |
| | | import android.content.Context |
| | | import android.content.res.TypedArray |
| | | import android.os.Parcel |
| | | import android.os.Parcelable |
| | | import android.text.Editable |
| | | import android.util.AttributeSet |
| | | import android.util.Log |
| | | import android.view.LayoutInflater |
| | | import android.view.View |
| | | import android.widget.EditText |
| | |
| | | |
| | | class MyCustomEditText : LinearLayout{ |
| | | |
| | | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context,attrs,defStyleAttr,defStyleRes) { |
| | | mcontext = context |
| | | init() |
| | | private val TAG= "MyCustomEditText" |
| | | |
| | | constructor(context: Context) : this(context, null) |
| | | constructor(context: Context, attributeSet: AttributeSet?) : this(context, attributeSet, 0) |
| | | |
| | | constructor(context: Context, attributeSet: AttributeSet?, defStyleAttr: Int):super(context,attributeSet,defStyleAttr){ |
| | | init(context,attributeSet) |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // true就是显示 false不显示 |
| | | var visiblity:Boolean = true |
| | |
| | | var str:String="" |
| | | var desstr:String="" |
| | | |
| | | var mcontext:Context?= null |
| | | var txtDes:TextView? = null |
| | | var txtDesUnit:TextView? = null |
| | | var et_num:EditText? = null |
| | | var view: View? = null |
| | | override fun onFinishInflate() { |
| | | super.onFinishInflate() |
| | | |
| | | |
| | | fun init(context: Context, attributeSet: AttributeSet?){ |
| | | Log.i(TAG,"myCustomEditText z自定义---------") |
| | | view = LayoutInflater.from(context).inflate(R.layout.layout_mycustom_et,this,true) |
| | | |
| | | txtDes = view?.findViewById(R.id.tv_des_et) |
| | | txtDesUnit = view?.findViewById(R.id.tv_unit) |
| | | et_num = view?.findViewById(R.id.et_num) |
| | | |
| | | var a = context.obtainStyledAttributes(attributeSet,R.styleable.mycustom_et) |
| | | //获取是否要显示单位 |
| | | visiblity = a!!.getBoolean(R.styleable.mycustom_et_txt_unit,true) |
| | | str = a!!.getString(R.styleable.mycustom_et_txt) |
| | | desstr = a!!.getString(R.styleable.mycustom_et_txt_des) |
| | | |
| | | var desunit = a!!.getString(R.styleable.mycustom_et_txt_unit_des) |
| | | // var width = a!!.getString(R.styleable.mycustom_et_view_width) |
| | | // var height = a!!.getString(R.styleable.mycustom_et_view_height) |
| | | |
| | | Log.i(TAG,"txtDes=$desstr") |
| | | Log.i(TAG,"str=$str") |
| | | Log.i(TAG,"visiblity=$visiblity") |
| | | |
| | | |
| | | |
| | | when(visiblity){ |
| | | true->txtDesUnit?.visibility = View.VISIBLE |
| | | true->{ |
| | | txtDesUnit?.visibility = View.VISIBLE |
| | | txtDesUnit?.text = desunit |
| | | } |
| | | else-> txtDesUnit?.visibility = View.GONE |
| | | } |
| | | |
| | | txtDes?.text = desstr |
| | | et_num?.text = Editable.Factory.getInstance().newEditable(str) |
| | | |
| | | a.recycle() |
| | | |
| | | |
| | | } |
| | | |
| | | fun init(){ |
| | | view = LayoutInflater.from(mcontext).inflate(R.layout.layout_mycustom_et,null) |
| | | |
| | | var attributeSet = mcontext?.obtainStyledAttributes(R.styleable.mycustom_et) |
| | | //获取是否要显示单位 |
| | | visiblity = attributeSet?.getBoolean(R.styleable.mycustom_et_txt_unit,true)!! |
| | | str = attributeSet?.getString(R.styleable.mycustom_et_txt) |
| | | desstr = attributeSet?.getString(R.styleable.mycustom_et_txt_des) |
| | | |
| | | |
| | | fun updateStr(str:String){ |
| | | et_num?.text = Editable.Factory.getInstance().newEditable(str) |
| | | invalidate() |
| | | } |
| | | |
| | | } |