com.google.android.material.bottomnavigation.BottomNavigationItemView Java Examples
The following examples show how to use
com.google.android.material.bottomnavigation.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: BottomNavigationViewInner.java From smart-farmer-android 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 */ // 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: BottomNavigationActivity.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
@Override public void setAppsName(String name) { bottomNavigationView.getMenu() .getItem(4) .setTitle(mapAppsName(name)); BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0); for (int i = 0; i < menuView.getChildCount(); i++) { BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i); View largeLabel = item.findViewById(R.id.largeLabel); View smallLabel = item.findViewById(R.id.smallLabel); if (largeLabel instanceof TextView) { largeLabel.setPadding(0, 0, 0, 0); ((TextView) largeLabel).setEllipsize(TextUtils.TruncateAt.END); } if (smallLabel instanceof TextView) { smallLabel.setPadding(0, 0, 0, 0); ((TextView) smallLabel).setEllipsize(TextUtils.TruncateAt.END); } } }
Example #3
Source File: BottomNavigationViewInner.java From smart-farmer-android 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, "buttons"); return mButtons; }
Example #4
Source File: BottomNavigationViewInner.java From smart-farmer-android 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, "icon"); return mIcon; }
Example #5
Source File: BottomNavigationViewInner.java From smart-farmer-android 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, "smallLabel"); return mSmallLabel; }
Example #6
Source File: BottomNavigationViewInner.java From smart-farmer-android 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, "largeLabel"); return mLargeLabel; }
Example #7
Source File: BottomNavigationViewInner.java From smart-farmer-android 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 #8
Source File: BottomNavigationViewInner.java From smart-farmer-android with Apache License 2.0 | 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 #9
Source File: BottomNavigationViewEx.java From smart-farmer-android with Apache License 2.0 | 5 votes |
@Override public BottomNavigationItemView[] getBottomNavigationItemViews() { try { return super.getBottomNavigationItemViews(); } catch (Exception e) { return null; } }
Example #10
Source File: BottomNavigationViewEx.java From smart-farmer-android with Apache License 2.0 | 5 votes |
@Override public BottomNavigationItemView getBottomNavigationItemView(int position) { try { return super.getBottomNavigationItemView(position); } catch (Exception e) { return null; } }
Example #11
Source File: MainActivity.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
private void setupUpdatesNotification() { BottomNavigationMenuView appsView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0); BottomNavigationItemView appsItemView = (BottomNavigationItemView) appsView.getChildAt(BottomNavigationMapper.APPS_POSITION); updatesBadge = LayoutInflater.from(this) .inflate(R.layout.updates_badge, appsView, false); updatesNumber = updatesBadge.findViewById(R.id.updates_badge); appsItemView.addView(updatesBadge); appsItemView.setVisibility(View.VISIBLE); }
Example #12
Source File: BottomNavigationViewInner.java From smart-farmer-android with Apache License 2.0 | 4 votes |
/** * change the visibility of text * * @param visibility */ public BottomNavigationViewInner setTextVisibility(boolean visibility) { this.textVisibility = visibility; /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mButtons private BottomNavigationItemView[] mButtons; 3. set text size in mButtons private final TextView mLargeLabel private final TextView mSmallLabel 4. change mItemHeight to only icon size in mMenuView */ // 1. get mMenuView BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. change field mShiftingMode value in mButtons for (BottomNavigationItemView button : mButtons) { TextView mLargeLabel = getField(button.getClass(), button, "largeLabel"); TextView mSmallLabel = getField(button.getClass(), button, "smallLabel"); if (!visibility) { // if not record the font size, record it if (!visibilityTextSizeRecord && !animationRecord) { visibilityTextSizeRecord = true; mLargeLabelSize = mLargeLabel.getTextSize(); mSmallLabelSize = mSmallLabel.getTextSize(); } // if not visitable, set font size to 0 mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0); mSmallLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, 0); } else { // if not record the font size, we need do nothing. if (!visibilityTextSizeRecord) { break; } // restore it mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeLabelSize); mSmallLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSmallLabelSize); } } // 4 change mItemHeight to only icon size in mMenuView if (!visibility) { // if not record mItemHeight if (!visibilityHeightRecord) { visibilityHeightRecord = true; mItemHeight = getItemHeight(); } // change mItemHeight to only icon size in mMenuView // private final int mItemHeight; // change mItemHeight // System.out.println("mLargeLabel.getMeasuredHeight():" + getFontHeight(mSmallLabelSize)); setItemHeight(mItemHeight - getFontHeight(mSmallLabelSize)); } else { // if not record the mItemHeight, we need do nothing. if (!visibilityHeightRecord) { return this; } // restore mItemHeight setItemHeight(mItemHeight); } mMenuView.updateMenuView(); return this; }
Example #13
Source File: BottomNavigationViewInner.java From smart-farmer-android with Apache License 2.0 | 4 votes |
/** * enable or disable click item animation(text scale and icon move animation in no item shifting mode) * * @param enable It means the text won't scale and icon won't move when active it in no item shifting mode if false. */ public BottomNavigationViewInner enableAnimation(boolean enable) { /* 1. get field in this class private final BottomNavigationMenuView mMenuView; 2. get field in mButtons private BottomNavigationItemView[] mButtons; 3. chang mShiftAmount to 0 in mButtons private final int mShiftAmount change mScaleUpFactor and mScaleDownFactor to 1f in mButtons private final float mScaleUpFactor private final float mScaleDownFactor 4. change label font size in mButtons private final TextView mLargeLabel private final TextView mSmallLabel */ // 1. get mMenuView BottomNavigationMenuView mMenuView = getBottomNavigationMenuView(); // 2. get mButtons BottomNavigationItemView[] mButtons = getBottomNavigationItemViews(); // 3. change field mShiftingMode value in mButtons for (BottomNavigationItemView button : mButtons) { TextView mLargeLabel = getField(button.getClass(), button, "largeLabel"); TextView mSmallLabel = getField(button.getClass(), button, "smallLabel"); // if disable animation, need animationRecord the source value if (!enable) { if (!animationRecord) { animationRecord = true; mShiftAmount = getField(button.getClass(), button, "shiftAmount"); mScaleUpFactor = getField(button.getClass(), button, "scaleUpFactor"); mScaleDownFactor = getField(button.getClass(), button, "scaleDownFactor"); mLargeLabelSize = mLargeLabel.getTextSize(); mSmallLabelSize = mSmallLabel.getTextSize(); // System.out.println("mShiftAmount:" + mShiftAmount + " mScaleUpFactor:" // + mScaleUpFactor + " mScaleDownFactor:" + mScaleDownFactor // + " mLargeLabel:" + mLargeLabelSize + " mSmallLabel:" + mSmallLabelSize); } // disable setField(button.getClass(), button, "shiftAmount", 0); setField(button.getClass(), button, "scaleUpFactor", 1); setField(button.getClass(), button, "scaleDownFactor", 1); // let the mLargeLabel font size equal to mSmallLabel mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSmallLabelSize); // debug start // mLargeLabelSize = mLargeLabel.getTextSize(); // System.out.println("mLargeLabel:" + mLargeLabelSize); // debug end } else { // haven't change the value. It means it was the first call this method. So nothing need to do. if (!animationRecord) { return this; } // enable animation setField(button.getClass(), button, "shiftAmount", mShiftAmount); setField(button.getClass(), button, "scaleUpFactor", mScaleUpFactor); setField(button.getClass(), button, "scaleDownFactor", mScaleDownFactor); // restore mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeLabelSize); } } mMenuView.updateMenuView(); return this; }
Example #14
Source File: BottomNavigationViewInner.java From smart-farmer-android with Apache License 2.0 | 2 votes |
/** * get private mButton in mMenuView at position * * @param position * @return */ public BottomNavigationItemView getBottomNavigationItemView(int position) { return getBottomNavigationItemViews()[position]; }