简体   繁体   中英

Android - Changing item title in bottom navigation bar

I have 2 fragments between which I can navigate with a bottom navigation bar. I also have an overflow menu with an item which shows an edittext dialog.

I want that when I write and validate text in the dialog, the currently displayed fragment's item on the nav bar changes of title. I don't know how to change text of a specific item.

I hope my question is understandable. I have been searching through SO but I didn't find any corresponding answers.

In Kotlin

bottom_nav_view.menu.findItem(R.id.bottom_nav_item).title = "TITTLE"

in Java

bottom_nav_view.getMenu().findItem(R.id.bottom_nav_item).setTitle( "TITTLE")

If you define an id for the item you want to change in the layouts menu (add the line android:id="@+id/myid"), you can find that item in the code by using findViewById (R.id.myid). Then, just set the new the title depending on what the item is.

Without any code I can only guess that you setup a ViewPager with the TabLayout method yourTabLayout.setupWithViewPager(yourViewPagerAdapter); .

If it is so, you can simply set a title using yourTabLayout.getTabAt(position).setText(yourTitle); where position is 0 for first tab and 1 for second tab. If you post some code I can try to specify my answer on your code and the way you are adding the fragments to your activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM