xml:

<jp.co.view.TitleLayout
android: />
TitleLayout:
package jp.co.view

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import jp.co.hyakujushibank.securestarter.R

class TitleLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
private var barImg: ImageView? = null
private var titleTv: TextView? = null
private var closeTv: TextView? = null

init {
LayoutInflater.from(context).inflate(R.layout.layout_title, this)
val activity = (getContext() as Activity)
val backImg = findViewById(R.id.backImg) as ImageView
val closeTv = findViewById(R.id.closeTv) as TextView
val titleTv = findViewById(R.id.titleTv) as TextView
val barImg = findViewById(R.id.barImg) as ImageView
this.barImg = barImg
this.titleTv = titleTv
this.closeTv = closeTv
backImg.setOnClickListener { activity.finish() }
}

fun setBarImageResource(resource: Int) {
barImg!!.setImageResource(resource)
}

fun setTitle(title: String) {
titleTv!!.text = title
}

fun setCloseInvisible(){
closeTv!!.visibility=View.INVISIBLE
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro></LinearLayout>
 
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
猜你喜欢
  • 2021-05-22
  • 2021-08-20
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
相关资源
相似解决方案