Android 停止BottomNavigationView在单击时增加项目字体大小
BottomNavigationView的默认行为使项目字体大小在单击时增加,导致一些较长的标题被截断 我想避免字体大小增加,我该怎么做Android 停止BottomNavigationView在单击时增加项目字体大小,android,kotlin,tabs,font-size,bottomnavigationview,Android,Kotlin,Tabs,Font Size,Bottomnavigationview,BottomNavigationView的默认行为使项目字体大小在单击时增加,导致一些较长的标题被截断 我想避免字体大小增加,我该怎么做 谢谢 使用以下键在维度文件中添加文本大小 <dimen name="design_bottom_navigation_active_text_size" tools:override="true">12sp</dimen> <dimen name="design_bottom_navigation_text_size" tool
谢谢 使用以下键在维度文件中添加文本大小
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">12sp</dimen>
<dimen name="design_bottom_navigation_text_size" tools:override="true">12sp</dimen>
现在不需要使用反射来禁用移位
import android.annotation.SuppressLint;
import android.support.design.internal.BottomNavigationItemView;
import android.support.design.internal.BottomNavigationMenuView;
import android.support.design.widget.BottomNavigationView;
import android.util.Log;
import java.lang.reflect.Field;
public class BottomNavigationViewHelper {
@SuppressLint("RestrictedApi")
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.setShifting(false);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("Error BottomBar", e.getLocalizedMessage());
} catch (IllegalAccessException e) {
Log.e("Error BottomBar", e.getLocalizedMessage());
}
}
}
从支持库28.0.0
或材料库添加了新方法
setLabelVisibilityMode()
检查
你可以像这样使用它
bottomNavigationView.setLabelVisibilityMode(LABEL_VISIBILITY_UNLABELED);
它工作,但不幸的是,有一个轻微的闪烁时,点击该项目。有可能防止这种情况吗?
bottomNavigationView.setLabelVisibilityMode(LABEL_VISIBILITY_UNLABELED);