我为我的应用使用底部导航视图,并希望删除图标下的文字。我在互联网上寻找它但仍无法找到解决方案。有没有人用来处理这个请给我你的解决方案。
我想要的就是这样:
我的代码在这里: 主要布局包含recyclerview和bottomnavigationview:
<LinearLayout
android:weightSum="10"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="20dp"
android:layout_weight="8.5"
android:id="@+id/recyclerview_menu"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.BottomNavigationView
android:background="@color/whiteColor"
android:id="@+id/bottom_navigation_bar"
android:layout_weight="1.5"
app:menu="@menu/menu_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp">
</android.support.design.widget.BottomNavigationView>
</LinearLayout>
这是底部导航菜单:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorites"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Home"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_schedules"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_music"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Save"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_me"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title="Me"
app:showAsAction="ifRoom" />
在MainActivity中:
mBottomBar = (BottomNavigationView)
findViewById(R.id.bottom_navigation_bar);
disableShiftMode(mBottomBar);
public 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);
item.setShiftingMode(false);
// set once again checked value, so view will be updated
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("Luan", "Unable to get shift mode field");
} catch (IllegalAccessException e) {
Log.e("Luan", "Unable to change value of shift mode");
}
}
答案 0 :(得分:7)
将“ app:labelVisibilityMode”设置为“ unlabeled”
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="unlabeled"/>
答案 1 :(得分:5)
删除菜单项中的标题。然后将padding top应用于bottomnavigationview,如下所示
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorites"
android:tittle=""
android:enabled="true"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_schedules"
android:tittle=""
android:enabled="true"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_music"
android:tittle=""
android:enabled="true"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_me"
android:tittle=""
android:enabled="true"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom" />
在底部导航视图中
<android.support.design.widget.BottomNavigationView
android:background="@color/whiteColor"
android:id="@+id/bottom_navigation_bar"
android:layout_weight="1.5"
android:paddingTop="16dp"
app:menu="@menu/menu_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp">
答案 2 :(得分:0)
您需要做的就是将其添加到BottomNavigationView中,标题和烦人的动画都消失了app:labelVisibilityMode="unlabeled"
答案 3 :(得分:-2)
我找到解决方案请检查以下小改动。
首先在bottomnavigation菜单中更改xml:
更新了xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorites"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title=""
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_schedules"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title=""
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_music"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title=""
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_me"
android:enabled="true"
android:icon="@drawable/ic_search"
android:title=""
app:showAsAction="ifRoom" />
</menu>