Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomView: LinearLayout {
- private var drawable: Drawable? = null
- private var text: String? = null
- constructor(context: Context) : super(context) {
- init(context, null)
- }
- constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
- init(context, attrs)
- }
- constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
- init(context, attrs)
- }
- constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
- init(context, attrs)
- }
- private fun init(context: Context, attrs: AttributeSet?) {
- val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0)
- try {
- drawable= typedArray.getDrawable(R.styleable.CustomView_android_src)
- text= typedArray.getString(R.styleable.CustomView_android_text)
- } finally {
- typedArray.recycle()
- }
- View.inflate(context, R.layout.view_list_btn, this)
- (findViewById(R.id.imgIcon) as ImageView).apply { setImageDrawable(drawable) }
- (findViewById(R.id.tvTitle) as TextView).apply { setText(text) }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement