use of android.support.design.internal.BottomNavigationMenuView in project CustomViews by AndroidStudy233.
the class FragmentSurppotAct method disableShiftMode.
/**
* 关闭BottomNavigationView的切换动画
*
* @param view BottomNavigationView
*/
private 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);
item.setShiftingMode(false);
item.setChecked(item.getItemData().isChecked());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.
the class BottomNavigationViewEx method enableItemShiftingMode.
/**
* 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();
}
use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.
the class BottomNavigationViewEx method enableAnimation.
/**
* 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 void 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, "mLargeLabel");
TextView mSmallLabel = getField(button.getClass(), button, "mSmallLabel");
// if disable animation, need animationRecord the source value
if (!enable) {
if (!animationRecord) {
animationRecord = true;
mShiftAmount = getField(button.getClass(), button, "mShiftAmount");
mScaleUpFactor = getField(button.getClass(), button, "mScaleUpFactor");
mScaleDownFactor = getField(button.getClass(), button, "mScaleDownFactor");
mLargeLabelSize = mLargeLabel.getTextSize();
mSmallLabelSize = mSmallLabel.getTextSize();
// System.out.println("mShiftAmount:" + mShiftAmount + " mScaleUpFactor:"
// + mScaleUpFactor + " mScaleDownFactor:" + mScaleDownFactor
// + " mLargeLabel:" + mLargeLabelSize + " mSmallLabel:" + mSmallLabelSize);
}
// disable
setField(button.getClass(), button, "mShiftAmount", 0);
setField(button.getClass(), button, "mScaleUpFactor", 1);
setField(button.getClass(), button, "mScaleDownFactor", 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;
// enable animation
setField(button.getClass(), button, "mShiftAmount", mShiftAmount);
setField(button.getClass(), button, "mScaleUpFactor", mScaleUpFactor);
setField(button.getClass(), button, "mScaleDownFactor", mScaleDownFactor);
// restore
mLargeLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX, mLargeLabelSize);
}
}
mMenuView.updateMenuView();
}
use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.
the class BottomNavigationViewEx method setItemHeight.
/**
* set menu item height
*
* @param height in px
*/
public void setItemHeight(int height) {
// 1. get mMenuView
final BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
// 2. set private final int mItemHeight in mMenuView
setField(mMenuView.getClass(), mMenuView, "mItemHeight", height);
mMenuView.updateMenuView();
}
use of android.support.design.internal.BottomNavigationMenuView in project weiui by kuaifan.
the class BottomNavigationViewEx method refreshTextViewVisibility.
private void refreshTextViewVisibility() {
if (!textVisibility)
return;
// 1. get mMenuView
BottomNavigationMenuView mMenuView = getBottomNavigationMenuView();
// 2. get mButtons
BottomNavigationItemView[] mButtons = getBottomNavigationItemViews();
int currentItem = getCurrentItem();
// 3. get field mShiftingMode and TextView in mButtons
for (BottomNavigationItemView button : mButtons) {
TextView mLargeLabel = getField(button.getClass(), button, "mLargeLabel");
TextView mSmallLabel = getField(button.getClass(), button, "mSmallLabel");
mLargeLabel.clearAnimation();
mSmallLabel.clearAnimation();
// mShiftingMode
boolean mShiftingMode = getField(button.getClass(), button, "mShiftingMode");
boolean selected = button.getItemPosition() == currentItem;
if (mShiftingMode) {
if (selected) {
mLargeLabel.setVisibility(VISIBLE);
} else {
mLargeLabel.setVisibility(INVISIBLE);
}
mSmallLabel.setVisibility(INVISIBLE);
} else {
if (selected) {
mLargeLabel.setVisibility(VISIBLE);
mSmallLabel.setVisibility(INVISIBLE);
} else {
mLargeLabel.setVisibility(INVISIBLE);
mSmallLabel.setVisibility(VISIBLE);
}
}
}
}
Aggregations