簡體   English   中英

中心底部導航欄圖標

[英]Center bottom navigation bar icons

我正在嘗試使所有圖標居中,我已經通過使用以下代碼禁用了切換模式:

/**
 * This is done to remove the shift animation introduced by Android on the bottom navigation view
 * https://stackoverflow.com/a/41690461/4243027
 */
@SuppressLint("RestrictedApi")
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);
            item.setPadding(0,15,0,0);
            // 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);
    }
}

並將標題設置為“”

android:title=""

我也嘗試執行以下https://stackoverflow.com/a/40234361/4243027,但它也不起作用。

我的底部導航視圖如下所示:

底部導航欄

我正在使用implementation "com.android.support:design:27.0.1"

編輯:

正如您在“布局檢查器”中所看到的,圖標大小相同,為63x63像素,但選中的圖標的Y小5像素。

布局檢查器

從Design Support Library 28.0.0-alpha1開始,您可以使用該屬性

app:labelVisibilityMode =“ unlabeled”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM