android.support.design.internal.BottomNavigationItemView Java Examples
The following examples show how to use
android.support.design.internal.BottomNavigationItemView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 6 votes |
/** * get the current checked item position * * @return index of item, start from 0. */ public int getCurrentItem() { /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mMenuView private BottomNavigationItemView[] mButtons; 3. get menu and traverse it to get the checked one */ // 1. get mMenuView // BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. get menu and traverse it to get the checked one Menu menu = getMenu(); for (int i = 0; i < mButtons.length; i++) { if (menu.getItem(i).isChecked()) { return i; } } return 0; }
Example #2
Source File: BottomNavigationViewEx.java From playa with MIT License | 6 votes |
/** * enable the shifting mode for each item * * @param enable It will has a shift animation for item if true. Otherwise the item text always be shown. */ public void enableItemShiftingMode(boolean enable) { /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in this mMenuView private BottomNavigationItemView[] mButtons; 3. change field mShiftingMode value in mButtons private boolean mShiftingMode = true; */ // 1. get mMenuView BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. change field mShiftingMode value in mButtons for (BottomNavigationItemView button : mButtons) { setField(button.getClass(), button, "mShiftingMode", enable); } mMenuView.updateMenuView(); }
Example #3
Source File: BottomNavigationViewEx.java From playa with MIT License | 6 votes |
/** * get the current checked item position * * @return index of item, start from 0. */ public int getCurrentItem() { /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mMenuView private BottomNavigationItemView[] mButtons; 3. get menu and traverse it to get the checked one */ // 1. get mMenuView // BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. get menu and traverse it to get the checked one Menu menu = getMenu(); for (int i = 0; i < mButtons.length; i++) { if (menu.getItem(i).isChecked()) { return i; } } return 0; }
Example #4
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 6 votes |
/** * get the current checked item position * * @return index of item, start from 0. */ public int getCurrentItem() { /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mMenuView private BottomNavigationItemView[] mButtons; 3. get menu and traverse it to get the checked one */ // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. get menu and traverse it to get the checked one Menu menu = getMenu(); for (int i = 0; i < mButtons.length; i++) { if (menu.getItem(i).isChecked()) { return i; } } return 0; }
Example #5
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 6 votes |
/** * enable the shifting mode for each item * * @param enable It will has a shift animation for item if true. Otherwise the item text always be shown. */ public void enableItemShiftingMode(boolean enable) { /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in this mMenuView private BottomNavigationItemView[] mButtons; 3. change field mShiftingMode value in mButtons private boolean mShiftingMode = true; */ // 1. get mMenuView BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. change field mShiftingMode value in mButtons for (BottomNavigationItemView button : mButtons) { setField(button.getClass(), button, "mShiftingMode", enable); } mMenuView.updateMenuView(); }
Example #6
Source File: BottomSheetContentController.java From 365browser with Apache License 2.0 | 6 votes |
private void disableShiftingMode() { BottomNavigationMenuView menuView = (BottomNavigationMenuView) 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 the checked value so that the view will be updated. item.setChecked(item.getItemData().isChecked()); } } catch (NoSuchFieldException | IllegalAccessException e) { // Do nothing if reflection fails. } }
Example #7
Source File: MainActivity.java From MBEStyle with GNU General Public License v3.0 | 6 votes |
private void setBottomIconOriColor(BottomNavigationView bottomView) { try { Field mMenuViewField = BottomNavigationView.class.getDeclaredField("mMenuView"); mMenuViewField.setAccessible(true); BottomNavigationMenuView mMenuView = (BottomNavigationMenuView) mMenuViewField.get(bottomView); Field mButtonsField = BottomNavigationMenuView.class.getDeclaredField("mButtons"); mButtonsField.setAccessible(true); BottomNavigationItemView[] mButtons = (BottomNavigationItemView[]) mButtonsField.get(mMenuView); Field mIconField = BottomNavigationItemView.class.getDeclaredField("mIcon"); mIconField.setAccessible(true); for (BottomNavigationItemView item : mButtons) { ImageView mIcon = (ImageView) mIconField.get(item); mIcon.setImageTintList(null); } } catch (Exception e) { e.printStackTrace(); } }
Example #8
Source File: BottomNavigationViewHelper.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
public static void disableShiftMode(Context context, BottomNavigationView view) { int color = ATHUtil.resolveColor(context, android.R.attr.textColorSecondary); setItemIconColors(view, color, ThemeStore.accentColor(context)); setItemTextColors(view, color, ThemeStore.accentColor(context)); 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); /*TextView smallText = (TextView) item.findViewById(R.id.smallLabel); smallText.setVisibility(View.GONE); TextView largeLabel = (TextView) item.findViewById(R.id.largeLabel); largeLabel.setVisibility(View.GONE); AppCompatImageView icon = (AppCompatImageView) item.getChildAt(0); FrameLayout.LayoutParams params = (BottomNavigationView.LayoutParams) icon.getLayoutParams(); params.gravity = Gravity.CENTER;*/ //noinspection RestrictedApi item.setShiftingMode(false); // set once again checked value, so view will be updated //noinspection RestrictedApi item.setChecked(item.getItemData().isChecked()); } } catch (NoSuchFieldException | IllegalAccessException ignored) { ignored.printStackTrace(); } }
Example #9
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 5 votes |
/** * set margin top for icon * * @param position * @param marginTop in px */ public BottomNavigationViewInner setIconMarginTop(int position, int marginTop) { /* 1. BottomNavigationItemView 2. private final int mDefaultMargin; */ BottomNavigationItemView itemView = getBottomNavigationItemView(position); setField(BottomNavigationItemView.class, itemView, "defaultMargin", marginTop); mMenuView.updateMenuView(); return this; }
Example #10
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * get icon at position * * @param position * @return */ public ImageView getIconAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private ImageView mIcon; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); ImageView mIcon = getField(BottomNavigationItemView.class, mButtons, "mIcon"); return mIcon; }
Example #11
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * get small label at position * Each item has tow label, one is large, another is small. * * @param position * @return */ public TextView getSmallLabelAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private final TextView mSmallLabel; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); TextView mSmallLabel = getField(BottomNavigationItemView.class, mButtons, "mSmallLabel"); return mSmallLabel; }
Example #12
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * get large label at position * Each item has tow label, one is large, another is small. * * @param position * @return */ public TextView getLargeLabelAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private final TextView mLargeLabel; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); TextView mLargeLabel = getField(BottomNavigationItemView.class, mButtons, "mLargeLabel"); return mLargeLabel; }
Example #13
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * return item count * * @return */ public int getItemCount() { BottomNavigationItemView[] bottomNavigationItemViews = getBottomNavigationItemViews(); if (null == bottomNavigationItemViews) return 0; return bottomNavigationItemViews.length; }
Example #14
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * set margin top for icon * @param position * @param marginTop in px */ public void setIconMarginTop(int position, int marginTop) { /* 1. BottomNavigationItemView 2. private final int mDefaultMargin; */ BottomNavigationItemView itemView = getBottomNavigationItemView(position); setField(BottomNavigationItemView.class, itemView, "mDefaultMargin", marginTop); mMenuView.updateMenuView(); }
Example #15
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 5 votes |
/** * get icon at position * * @param position * @return */ public ImageView getIconAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private ImageView mIcon; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); ImageView mIcon = getField(BottomNavigationItemView.class, mButtons, "icon"); return mIcon; }
Example #16
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 5 votes |
/** * return item count * * @return */ public int getItemCount() { BottomNavigationItemView[] bottomNavigationItemViews = getBottomNavigationItemViews(); if (null == bottomNavigationItemViews) return 0; return bottomNavigationItemViews.length; }
Example #17
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 5 votes |
/** * get large label at position * Each item has tow label, one is large, another is small. * * @param position * @return */ public TextView getLargeLabelAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private final TextView mLargeLabel; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); TextView mLargeLabel = getField(BottomNavigationItemView.class, mButtons, "largeLabel"); return mLargeLabel; }
Example #18
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 5 votes |
/** * get private mButtons in mMenuView * * @return */ public BottomNavigationItemView[] getBottomNavigationItemViews() { if (null != mButtons) return mButtons; /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; */ BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); mButtons = getField(mMenuView.getClass(), mMenuView, "buttons"); return mButtons; }
Example #19
Source File: BottomNavigationViewInner.java From BottomNavigationViewEx with MIT License | 5 votes |
/** * get small label at position * Each item has tow label, one is large, another is small. * * @param position * @return */ public TextView getSmallLabelAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private final TextView mSmallLabel; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); TextView mSmallLabel = getField(BottomNavigationItemView.class, mButtons, "smallLabel"); return mSmallLabel; }
Example #20
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * get private mButtons in mMenuView * * @return */ public BottomNavigationItemView[] getBottomNavigationItemViews() { if (null != mButtons) return mButtons; /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; */ BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); mButtons = getField(mMenuView.getClass(), mMenuView, "mButtons"); return mButtons; }
Example #21
Source File: BottomNavigationViewEx.java From Cashew with Apache License 2.0 | 5 votes |
/** * set the current checked item * * @param item start from 0. */ public void setCurrentItem(int item) { // check bounds if (item < 0 || item >= getMaxItemCount()) { throw new ArrayIndexOutOfBoundsException("item is out of bounds, we expected 0 - " + (getMaxItemCount() - 1) + ". Actually " + item); } /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mMenuView private BottomNavigationItemView[] mButtons; private final OnClickListener mOnClickListener; 3. call mOnClickListener.onClick(); */ // 1. get mMenuView BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // get mOnClickListener OnClickListener mOnClickListener = getField(mMenuView.getClass(), mMenuView, "mOnClickListener"); // System.out.println("mMenuView:" + mMenuView + " mButtons:" + mButtons + " mOnClickListener" + mOnClickListener); // 3. call mOnClickListener.onClick(); mOnClickListener.onClick(mButtons[item]); }
Example #22
Source File: BottomNavigationViewEx.java From BottomNavigationViewEx with MIT License | 5 votes |
@Override public BottomNavigationItemView[] getBottomNavigationItemViews() { try { return super.getBottomNavigationItemViews(); } catch (Exception e) { return null; } }
Example #23
Source File: BottomNavigationViewEx.java From BottomNavigationViewEx with MIT License | 5 votes |
@Override public BottomNavigationItemView getBottomNavigationItemView(int position) { try { return super.getBottomNavigationItemView(position); } catch (Exception e) { return null; } }
Example #24
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * set margin top for icon * * @param position * @param marginTop in px */ public void setIconMarginTop(int position, int marginTop) { /* 1. BottomNavigationItemView 2. private final int mDefaultMargin; */ BottomNavigationItemView itemView = getBottomNavigationItemView(position); setField(BottomNavigationItemView.class, itemView, "mDefaultMargin", marginTop); mMenuView.updateMenuView(); }
Example #25
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * return item count * * @return */ public int getItemCount() { BottomNavigationItemView[] bottomNavigationItemViews = getBottomNavigationItemViews(); if (null == bottomNavigationItemViews) return 0; return bottomNavigationItemViews.length; }
Example #26
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * get large label at position * Each item has tow label, one is large, another is small. * * @param position * @return */ public TextView getLargeLabelAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private final TextView mLargeLabel; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); TextView mLargeLabel = getField(BottomNavigationItemView.class, mButtons, "mLargeLabel"); return mLargeLabel; }
Example #27
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * get small label at position * Each item has tow label, one is large, another is small. * * @param position * @return */ public TextView getSmallLabelAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private final TextView mSmallLabel; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); TextView mSmallLabel = getField(BottomNavigationItemView.class, mButtons, "mSmallLabel"); return mSmallLabel; }
Example #28
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * get icon at position * * @param position * @return */ public ImageView getIconAt(int position) { /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; * 3 private ImageView mIcon; */ BottomNavigationItemView mButtons = getBottomNavigationItemView(position); ImageView mIcon = getField(BottomNavigationItemView.class, mButtons, "mIcon"); return mIcon; }
Example #29
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * get private mButtons in mMenuView * * @return */ public BottomNavigationItemView[] getBottomNavigationItemViews() { if (null != mButtons) return mButtons; /* * 1 private final BottomNavigationMenuView mMenuView; * 2 private BottomNavigationItemView[] mButtons; */ BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); mButtons = getField(mMenuView.getClass(), mMenuView, "mButtons"); return mButtons; }
Example #30
Source File: BottomNavigationViewEx.java From playa with MIT License | 5 votes |
/** * set the current checked item * * @param item start from 0. */ public void setCurrentItem(int item) { // check bounds if (item < 0 || item >= getMaxItemCount()) { throw new ArrayIndexOutOfBoundsException("item is out of bounds, we expected 0 - " + (getMaxItemCount() - 1) + ". Actually " + item); } /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mMenuView private BottomNavigationItemView[] mButtons; private final OnClickListener mOnClickListener; 3. call mOnClickListener.onClick(); */ // 1. get mMenuView BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // get mOnClickListener OnClickListener mOnClickListener = getField(mMenuView.getClass(), mMenuView, "mOnClickListener"); // System.out.println("mMenuView:" + mMenuView + " mButtons:" + mButtons + " mOnClickListener" + mOnClickListener); // 3. call mOnClickListener.onClick(); mOnClickListener.onClick(mButtons[item]); }