How to fix the position of bottom navigation view menu items?

这一生的挚爱 提交于 2020-01-04 07:47:12

问题


I have a bottom navigation view in my home page, there are four menu items. On onCreate(), the four menu items are not in fixed position, the label is shown only when it is tapped on and it changes the position. I want them to remain fixed in position with their labels visible, not changing position upon touching. Here are my xml codes:

     <?xml version="1.0" encoding="utf-8"?>
       <menu xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       xmlns:design="http://schemas.android.com/tools">
       <item
        android:id="@+id/menu_home"
        android:title="Home"
        android:enabled="true"
        android:icon="@drawable/home_icon"
        app:showAsAction="always"/>
    <item
        android:id="@+id/menu_wallet"
        android:title="Wallet"
        android:enabled="true"
        android:icon="@drawable/wallet_icon"
        app:showAsAction="always"/>

    <item
        android:id="@+id/menu_toto"
        android:title="Toto"
        android:enabled="true"
        android:icon="@drawable/toto_icon"
        app:showAsAction="always"/>
    <item
        android:id="@+id/menu_settings"
        android:title="Settings"
        android:enabled="true"
        android:icon="@drawable/setting_icon"
        app:showAsAction="always"/>
</menu>

and the main xml is like this:

<android.support.design.widget.BottomNavigationView
   android:id="@+id/navigation"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_alignParentBottom="true"
   app:itemBackground="@color/homenavigationbottom"
   app:itemTextColor="@android:color/white"
   android:fitsSystemWindows="true"
   app:menu="@menu/bottom_navigation_menu"/>

回答1:


Add the following tag in your activity_main.xml file code:

android:layout_gravity="bottom"

More info: https://developer.android.com/reference/android/support/design/widget/BottomNavigationView.html



来源:https://stackoverflow.com/questions/47159826/how-to-fix-the-position-of-bottom-navigation-view-menu-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!