Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

android - BottomNavigationView - How to uncheck all MenuItems and keep Titles being displayed?

As I liked the design from BottomNavigationView I decided to implement a new Menu for my App with it, instead of just using simple buttons.

I took this post as a guideline.

According to BottomNavigationView's documentation, its purpose is to

provide quick navigation between top-level views of an app. It is primarily designed for use on mobile.

In my case, I just want each MenuItem to launch an activity, but by default there is always one MenuItem selected:

enter image description here

I tried to set the color to white with:

app:itemIconTint="@color/white"
app:itemTextColor="@color/white"

Still, visibly selected MenuItem is different from others (Title size bigger), which is still bothering me:

enter image description here

I came with the idea to place a hidden MenuItem to select like:

<item
android:id="@+id/uncheckedItem"
android:title="" />

and make its view GONE:

 bottomNavigationView.getMenu().findItem(R.id.uncheckedItem).setChecked(true);
 bottomNavigationView.findViewById(R.id.uncheckedItem).setVisibility(View.GONE);

This makes all MenuItems unchecked, but by default BottomNavigationView is hidding Titles, as it has more than 3 MenuItems to display, even if the fourth MenuItem is settle to GONE:

enter image description here

So my question remains, is there away/hack to unselect all MenuItems and keep its titles being displayed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
mNavigationBottom.getMenu().setGroupCheckable(0, false, true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...