Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize the top navigation bar in Android

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian for you to introduce in detail "how to customize the top navigation bar in Android", the content is detailed, the steps are clear, the details are handled properly, I hope this "how to customize the top navigation bar in Android" article can help you solve your doubts, the following follows the editor's ideas slowly in depth, together to learn new knowledge.

The specific code is as follows:

Class HeaderBar @ JvmOverloads constructor (context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0): FrameLayout (context, attrs, defStyleAttr) {/ / rewrite constructors in java we usually rewrite three constructors / / in kotlin we can use @ JvmOverloads constructor (/ / context: Context, attrs: AttributeSet? = null The next two parameters we do not pass are default values / / define some variables private var isShowback = trueprivate var titleText: String? = nullprivate var rightText: String? = null// initialize the layout settings styleinit {/ / custom properties val typedArray = context.obtainStyledAttributes (attrs, R.styleable.HeaderBar) / / take out the properties defined in the layout isShowback = typedArray.getBoolean (R.styleable.HeaderBar_isShowBack) in the init method True) titleText = typedArray.getString (R.styleable.HeaderBar_titleText) rightText = typedArray.getString (R.styleable.HeaderBar_rightText) initView () typedArray.recycle ()} / / method to initialize the control private fun initView () {/ / populate the layout View.inflate (context, R.layout.layout_header_bar) This) mLeftIv.visibility = if (isShowback) View.VISIBLE else View.INVISIBLEtitleText?.let {mTitleTv.text = it} rightText?.let {mRightTv.text = itmRightTv.visibility = View.VISIBLE} mLeftIv.onClick {if (context is Activity) (context as Activity). Finish ()} fun getRightView (): TextView {return mRightTv}} here This article "how to customize the top navigation bar in Android" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about the article, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report