2017-06-13 87 views
2

我有我的bottomNavigationView:BottomNavigationView原始圖標的顏色

enter image description here

而且我加入這個類,以防止它做shiftingMode:

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

我只是想顯示原始圖標的顏色不這個選擇器,我怎麼能達到這個?

我的導航XML:

<android.support.design.widget.BottomNavigationView 
     android:id="@+id/bottomNavigation" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:menu="@menu/my_navigation_item" 
     android:layout_alignParentBottom="true"/> 

回答

14

你必須讓你的項目圖標的色彩列表null,您可以到達,從你bootomNav:

bottomNavigationView.setItemIconTintList(null); 
+1

感謝您的解決方案,它的工作原理!我試圖向XML添加:app:itemIconTint =「@ null」,但它不起作用。 – NightSkyDev

相關問題