Reputation: 2879
I try to use BottomNavigationView
but have some issues:
Activity xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.xxx.bottomnavigationbartest.BaseActivity">
<android.support.design.widget.BottomNavigationView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
bottom_navigation_main.xml:
<?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">
<item
android:id="@+id/action_one"
android:enabled="true"
android:title="one"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_two"
android:enabled="true"
android:title="two"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_three"
android:enabled="true"
android:title="three"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_new"
android:enabled="true"
android:title="new"
app:showAsAction="ifRoom" />
</menu>
If I have only three menu items(without action_new
) then all looks fine, but when I have four or more items then it looks like this:
So, I can see only one menu item in the same time. How can I fix it?
UPD:
build.gradle(Project):
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
build.gradle(Module):
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.github.ittianyu:BottomNavigationViewEx:1.2.1'
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.xxx.bottomnavigationbartest.BaseActivity">
<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
android:id="@+id/bnve"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
Upvotes: 2
Views: 1276
Reputation: 8106
The reason is, that BottomNavigationView
has a fixed size of 3. (Hardcoded mShiftingMode = mMenu.size() > 3
) You can either try to set
android:showAsAction="always|withText"
or disable shifting mode using
disableShiftMode()
Due several reasons and bugs i highly recommend you to use an external BottomNavigationView which is well tested like BottomNavigationViewEx.
This does also "fixes" the issue with the shifting animations and enables the use of a ViewPager.
After you have replaced it using BottomNavigationViewEx you can use
yourNavigationView.enableShiftingMode(false)
yourNavigationView.enableItemShiftingMode(false)
Upvotes: 1