[英]Android - Changing item title in bottom navigation bar
I have 2 fragments between which I can navigate with a bottom navigation bar. 我有2个片段,可在它们之间使用底部导航栏进行导航。 I also have an overflow menu with an item which shows an edittext dialog.
我也有一个带有项目的溢出菜单,其中显示了一个Edittext对话框。
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.
我一直在搜索SO,但没有找到任何相应的答案。
In Kotlin 在科特林
bottom_nav_view.menu.findItem(R.id.bottom_nav_item).title = "TITTLE"
in Java 在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). 如果在布局菜单中为要更改的项目定义了一个ID(添加行android:id =“ @ + id / myid”),则可以使用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);
没有任何代码,我只能猜测您使用
TabLayout
方法yourTabLayout.setupWithViewPager(yourViewPagerAdapter);
设置了ViewPager
yourTabLayout.setupWithViewPager(yourViewPagerAdapter);
. 。
If it is so, you can simply set a title using yourTabLayout.getTabAt(position).setText(yourTitle);
如果是这样,您可以简单地使用
yourTabLayout.getTabAt(position).setText(yourTitle);
设置标题yourTabLayout.getTabAt(position).setText(yourTitle);
where position
is 0
for first tab and 1
for second tab. 其中第一个标签页的
position
为0
,第二个标签页的position
为1
。 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. 如果您发布一些代码,我可以尝试在代码上指定答案,以及将片段添加到活动中的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.