gpt4 book ai didi

android - 选项卡在 Android 的 BottomNavigationView 中不是对称的

转载 作者:行者123 更新时间:2023-11-29 19:13:43 25 4
gpt4 key购买 nike

enter image description here

navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/navigation_clock"
android:icon="@drawable/time"
android:title="" />

<item android:id="@+id/navigation_medicine"
android:icon="@drawable/medicine"
android:title="" />

<item android:id="@+id/navigation_user"
android:icon="@drawable/users"
android:title="" />

<item android:id="@+id/navigation_setting"
android:icon="@drawable/setting"
android:title="" />

</menu>

activity_mail.xml BottomNavigationView component

<android.support.design.widget.BottomNavigationView android:id="@+id/navigation"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_marginEnd="0dp" android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:menu="@menu/navigation" />

when I added 3 tabs BottomNavigationView got symmetrical.but when it's come to 4 tabs BottomNavigationView not symmetrical.how can I solve that? I really appreciate your suggestions.Thanks in advance.

最佳答案

移除 BottomNavigationView 的默认动画

navigation = (BottomNavigationView) findViewById(R.id.navigation);
disableShiftMode(navigation);

方法

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);
}
}

来源https://stackoverflow.com/a/43491890/5423894

关于android - 选项卡在 Android 的 BottomNavigationView 中不是对称的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44321099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com