欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android自定義頂部導(dǎo)航欄控件實(shí)例代碼

 更新時(shí)間:2017年12月25日 16:19:04   作者:楊偉喬  
這篇文章主要介紹了Android自定義頂部導(dǎo)航欄控件實(shí)例代碼,需要的朋友可以參考下

下面一段代碼給大家介紹了android 自定義頂部導(dǎo)航欄控件功能,具體代碼如下所示:

class HeaderBar @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
//重寫構(gòu)造方法 在java里面 我們一般是重寫三個(gè)構(gòu)造方法//在kotlin中 我們可以使用@JvmOverloads constructor(
//     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
//  )后面的兩個(gè)參數(shù) 我們不傳的可以使用的是默認(rèn)值//定義一些變量private var isShowback = true
private var titleText: String? = null
private var rightText: String? = null
//初始化 在init方法中 初始化布局 設(shè)置style
init {
//自定義屬性val typedArray = context.obtainStyledAttributes(attrs, R.styleable.HeaderBar)
//取出在布局中定義的屬性isShowback = typedArray.getBoolean(R.styleable.HeaderBar_isShowBack, true)
titleText = typedArray.getString(R.styleable.HeaderBar_titleText)
rightText = typedArray.getString(R.styleable.HeaderBar_rightText)
initView()
typedArray.recycle()
}
//初始化控件的方法private fun initView() {
//填充布局View.inflate(context, R.layout.layout_header_bar, this)
mLeftIv.visibility = if (isShowback) View.VISIBLE else View.INVISIBLE
titleText?.let {
mTitleTv.text = it
}
rightText?.let {
mRightTv.text = it
mRightTv.visibility = View.VISIBLE
}
mLeftIv.onClick {
if (context is Activity)
(context as Activity).finish()
}
}
fun getRightView(): TextView {
return mRightTv
}
}

總結(jié)

以上所述是小編給大家介紹的Android自定義頂部導(dǎo)航欄控件實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論