本文整理汇总了Java中android.support.design.internal.BottomNavigationItemView.setChecked方法的典型用法代码示例。如果您正苦于以下问题:Java BottomNavigationItemView.setChecked方法的具体用法?Java BottomNavigationItemView.setChecked怎么用?Java BottomNavigationItemView.setChecked使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.design.internal.BottomNavigationItemView
的用法示例。
在下文中一共展示了BottomNavigationItemView.setChecked方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: disableShiftMode
import android.support.design.internal.BottomNavigationItemView; //导入方法依赖的package包/类
public static void disableShiftMode(BottomNavigationView navigationView) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigationView.getChildAt(0);
try {
Field shiftMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftMode.setAccessible(true);
shiftMode.setBoolean(menuView, false);
shiftMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView itemView = (BottomNavigationItemView) menuView.getChildAt(i);
itemView.setShiftingMode(false);
itemView.setChecked(itemView.getItemData().isChecked());
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
示例2: disableShiftMode
import android.support.design.internal.BottomNavigationItemView; //导入方法依赖的package包/类
public static void disableShiftMode(BottomNavigationView navigationView) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigationView.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 itemView = (BottomNavigationItemView) menuView.getChildAt(i);
itemView.setShiftingMode(false);
itemView.setChecked(itemView.getItemData().isChecked());
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
示例3: disableShiftMode
import android.support.design.internal.BottomNavigationItemView; //导入方法依赖的package包/类
/**
* 取消BottomNavigationView各item切换时的位移动效
*
* @param navigationView 底部导航栏视图
*/
public static void disableShiftMode(BottomNavigationView navigationView) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigationView.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 itemView = (BottomNavigationItemView) menuView.getChildAt(i);
itemView.setShiftingMode(false);
itemView.setChecked(itemView.getItemData().isChecked());
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
示例4: disableShiftingMode
import android.support.design.internal.BottomNavigationItemView; //导入方法依赖的package包/类
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.
}
}
示例5: addUnreadBadges
import android.support.design.internal.BottomNavigationItemView; //导入方法依赖的package包/类
/**
* Add the unread messages badges.
*/
@SuppressLint("RestrictedApi")
private void addUnreadBadges() {
final float scale = getResources().getDisplayMetrics().density;
int badgeOffsetX = (int) (18 * scale + 0.5f);
int badgeOffsetY = (int) (7 * scale + 0.5f);
removeMenuShiftMode();
int largeTextHeight = getResources().getDimensionPixelSize(android.support.design.R.dimen.design_bottom_navigation_active_text_size);
for (int menuIndex = 0; menuIndex < mBottomNavigationView.getMenu().size(); menuIndex++) {
try {
int itemId = mBottomNavigationView.getMenu().getItem(menuIndex).getItemId();
BottomNavigationItemView navigationItemView = mBottomNavigationView.findViewById(itemId);
navigationItemView.setShiftingMode(false);
Field marginField = navigationItemView.getClass().getDeclaredField("mDefaultMargin");
marginField.setAccessible(true);
marginField.setInt(navigationItemView, marginField.getInt(navigationItemView) + (largeTextHeight / 2));
marginField.setAccessible(false);
Field shiftAmountField = navigationItemView.getClass().getDeclaredField("mShiftAmount");
shiftAmountField.setAccessible(true);
shiftAmountField.setInt(navigationItemView, 0);
shiftAmountField.setAccessible(false);
navigationItemView.setChecked(navigationItemView.getItemData().isChecked());
View iconView = navigationItemView.findViewById(R.id.icon);
if (iconView.getParent() instanceof FrameLayout) {
UnreadCounterBadgeView badgeView = new UnreadCounterBadgeView(iconView.getContext());
// compute the new position
FrameLayout.LayoutParams iconViewLayoutParams = (FrameLayout.LayoutParams) iconView.getLayoutParams();
FrameLayout.LayoutParams badgeLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
badgeLayoutParams.setMargins(iconViewLayoutParams.leftMargin + badgeOffsetX, iconViewLayoutParams.topMargin - badgeOffsetY, iconViewLayoutParams.rightMargin, iconViewLayoutParams.bottomMargin);
badgeLayoutParams.gravity = iconViewLayoutParams.gravity;
((FrameLayout) iconView.getParent()).addView(badgeView, badgeLayoutParams);
mBadgeViewByIndex.put(itemId, badgeView);
}
} catch (Exception e) {
Log.e(LOG_TAG, "## addUnreadBadges failed " + e.getMessage());
}
}
refreshUnreadBadges();
}