Tim
Tim

Reputation: 163

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.

Upvotes: 2

Views: 4991

Answers (3)

svkaka
svkaka

Reputation: 4022

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")

Upvotes: 8

malliaridis
malliaridis

Reputation: 494

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.

Upvotes: 0

Tomatocurry1
Tomatocurry1

Reputation: 21

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.

Upvotes: 0

Related Questions