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ì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 超簡(jiǎn)單的幾行代碼搞定Android底部導(dǎo)航欄功能
- Android虛擬導(dǎo)航欄遮擋底部的輸入框的解決方法
- Android開發(fā)之判斷有無虛擬按鍵(導(dǎo)航欄)的實(shí)例
- Android實(shí)現(xiàn)簡(jiǎn)單底部導(dǎo)航欄 Android仿微信滑動(dòng)切換效果
- Android 沉浸式狀態(tài)欄與隱藏導(dǎo)航欄實(shí)例詳解
- Android中TabLayout+ViewPager 簡(jiǎn)單實(shí)現(xiàn)app底部Tab導(dǎo)航欄
- Android自定義ViewPagerIndicator實(shí)現(xiàn)炫酷導(dǎo)航欄指示器(ViewPager+Fragment)
- Android9.0 SystemUI 網(wǎng)絡(luò)信號(hào)欄定制修改的流程解析
- 解析Android 8.1平臺(tái)SystemUI 導(dǎo)航欄加載流程
相關(guān)文章
Android實(shí)現(xiàn)socket通信統(tǒng)一接口的方法
這篇文章主要介紹了Android實(shí)現(xiàn)socket通信統(tǒng)一接口?,實(shí)現(xiàn)了統(tǒng)一接口之后確實(shí)可以使后續(xù)修改實(shí)現(xiàn)更加方便,程序結(jié)構(gòu)也更加工程化,需要的朋友可以參考下2021-12-12
Android?studio實(shí)現(xiàn)簡(jiǎn)單計(jì)算器的編寫
這篇文章主要為大家詳細(xì)介紹了Android?studio實(shí)現(xiàn)簡(jiǎn)單計(jì)算器的編寫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05
android4.0混淆XmlPullParser報(bào)錯(cuò)原因分析解決
今天,用android4.0在proguard-project.txt中加入 -libraryjars libs/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar這句話后,混淆時(shí)報(bào)上面的錯(cuò)誤,下面與大家分享下具體的解決方法2013-06-06
Android實(shí)現(xiàn)簡(jiǎn)單QQ登錄頁面
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單QQ登錄頁面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Android中使用ShareSDK集成分享功能的實(shí)例代碼
下面小編就為大家分享一篇Android中使用ShareSDK集成分享功能的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01
Android使用注解進(jìn)行代碼檢查的實(shí)現(xiàn)方法
這篇文章主要介紹了Android如何使用注解進(jìn)行代碼檢查,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09
Kotlin開發(fā)實(shí)戰(zhàn)之hello world
這篇文章主要為大家詳細(xì)介紹了Kotlin開發(fā)實(shí)戰(zhàn)之hello world的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
android使用ExpandableListView控件實(shí)現(xiàn)小說目錄效果的例子
這篇文章主要介紹了android使用ExpandableListView控件實(shí)現(xiàn)小說目錄效果的例子,還可以實(shí)現(xiàn)二級(jí)列表展示效果,需要的朋友可以參考下2014-07-07

