dev*_*v90 1 java android android-intent android-layout android-fragments
我查看了stackoverflow,并找到了有关如何从默认设置中删除动画的解决方案bottom navigation.
现在我需要从底部导航中删除标题。我在底部导航xml文件的标题中设置了空字符串,但它不会改变图像的位置。我正在使用 v27
bottom navigation.删除文本后,我需要将图像居中。
这是我的代码。
//OnCreate
BottomNavigationViewHelper.removeShiftMode(bottomNavigationView);
Run Code Online (Sandbox Code Playgroud)
MainActivity 中的静态类
public static class BottomNavigationViewHelper {
@SuppressLint("RestrictedApi")
public static void removeShiftMode(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("BottomNav", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BottomNav", "Unable to change value of shift mode", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以尝试将 app:labelVisibilityMode 添加到“未标记”
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:labelVisibilityMode="unlabeled"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1578 次 |
| 最近记录: |