Space of null title under icons of menu item

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Space of null title under icons of menu item



I used the menu item like this:


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/tab_bookmarks"
android:icon="@drawable/bookmark"
android:title="@null"/>
<item
android:id="@+id/tab_shasha"
android:icon="@drawable/shasha"
android:height="54dp"
android:width="24dp"
android:title="@null"/>
<item
android:id="@+id/tab_home"
android:icon="@drawable/home"
android:title="@null"/>
<item
android:id="@+id/tab_tv"
android:icon="@drawable/tv"
android:title="@null"/>
<item
android:id="@+id/tab_more"
android:icon="@drawable/more"
android:title="@null"/>





and this is one of the drawable tused in item above like android:icon="@drawable/tv" so this is tv.xml:


<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_checked="true"
android:drawable="@drawable/ic_tab_tv_selected" />
<item
android:state_checked="false"
android:bottom="13dp"
android:drawable="@drawable/ic_tab_tv"/>
</selector>



and I use this menu in bottomNavigationView like this:


BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);

BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);

bottomNavigationView.setOnNavigationItemSelectedListener
(new BottomNavigationView.OnNavigationItemSelectedListener()
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item)
Fragment selectedFragment = null;
switch (item.getItemId())
case R.id.tab_bookmarks:
selectedFragment = BookmarksFragment.newInstance();
break;

case R.id.tab_home:
selectedFragment = AboutUs.newInstance();
break;


FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_layout, selectedFragment);
transaction.commit();
return true;

);



and everything work fine but as you can see the menu items they have icons but I set the title to "@null"
so the bottom bar have icons now and there are no texts below icon but it still have the space of empty title which lead to make icons smaller
so how can I set no title like make title space gone and won't take space and leave all of it for icon to be larger than now



this is a photo for my bottom bar:



enter image description here



you can see the space on null title under the icons so how to make all space for icon like the pink square around the tv icon to make it larger because I tried to change the width and height of items and other solutions but nothing work




1 Answer
1



Try to use this method:


public void updateBottomBar()
BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
if (menuView != null)
for (int i = 0; i < menuView.getChildCount(); i++)
BottomNavigationItemView menuItemView = (BottomNavigationItemView) menuView.getChildAt(i);
ImageView icon = menuItemView.findViewById(R.id.icon);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) icon.getLayoutParams();
params.gravity = Gravity.CENTER;





It must be called when tab position is changed.



Update



There is a more beautiful solution, it works with the support library 28.0.0-alpha1:


bottomNavigationView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);



or


<android.support.design.widget.BottomNavigationView
app:labelVisibilityMode="unlabeled" />



and remove your code BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);


BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);





please can you explain more
– GNDevs
Aug 6 at 17:39





The above code is applied after initialization bottomNavigationView. He finds and centers icons.
– UgAr0FF
Aug 7 at 9:15


bottomNavigationView





so you mean I should keep my code as I wrote it and just add the method you talked about to the code too? @UgAr0FF
– GNDevs
Aug 7 at 9:26





@GNDevs I'm update answer. I hope this helps.
– UgAr0FF
Aug 7 at 9:45






Add this parameter <dimen name="design_bottom_navigation_icon_size" tools:override="true">24dp</dimen> to the dimens.xml with the desired size, it will override the icon size.
– UgAr0FF
Aug 8 at 7:50


<dimen name="design_bottom_navigation_icon_size" tools:override="true">24dp</dimen>


dimens.xml






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered