以下のコードを試してください:
XMLファイル:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
xmlns:app="http://schemas.Android.com/apk/res-auto"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:orientation="vertical">
<Android.support.v7.widget.Toolbar
Android:id="@+id/toolbar"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:layout_gravity="top"
Android:background="@color/gray"
Android:foregroundGravity="top"
Android:gravity="top">
</Android.support.v7.widget.Toolbar>
<FrameLayout
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:layout_weight="1">
<FrameLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:id="@+id/fragment_container"
Android:layout_width="match_parent"
Android:layout_height="match_parent" />
</FrameLayout>
<LinearLayout
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
Android:orientation="horizontal">
<Android.support.design.widget.BottomNavigationView
Android:id="@+id/bottomnav"
Android:layout_width="0dp"
Android:layout_height="56dp"
Android:layout_weight="1"
Android:background="null"
app:itemIconTint="@color/green"
app:itemTextColor="@color/green"
app:menu="@menu/main">
</Android.support.design.widget.BottomNavigationView>
<ImageView
Android:layout_width="0dp"
Android:layout_height="56dp"
Android:layout_weight="0.5"
Android:src="@drawable/camera" />
<Android.support.design.widget.BottomNavigationView
Android:id="@+id/bottomnav1"
Android:layout_width="0dp"
Android:layout_height="56dp"
Android:layout_weight="1"
Android:background="null"
app:itemIconTint="@color/green"
app:itemTextColor="@color/green"
app:menu="@menu/main">
</Android.support.design.widget.BottomNavigationView>
</LinearLayout>
</LinearLayout>
ヘルパークラス:
public class BottomNavigationViewHelper {
public static void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
//noinspection RestrictedApi
item.setShiftingMode(false);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BNVHelper", "Unable to change value of shift mode", e);
}
}
}
活動中:
BottomNavigationView bnav = (BottomNavigationView) findViewById(R.id.bottomnav);
BottomNavigationViewHelper.disableShiftMode(bnav);
メニューファイル:
<item
Android:id="@+id/place"
Android:icon="@drawable/ic_place_black_24dp"
Android:title="Place"/>
<item
Android:id="@+id/home"
Android:icon="@drawable/ic_account_balance_black_24dp"
Android:title="Home"/>