Android
BottomNavigationView 아이콘 사이즈 수정법 (태블릿 대응)
그란.
2018. 10. 19. 11:42
BottomNavigationView 의 아이콘 사이즈는 내부적으로 하드코딩되어있다
그래서 drawable 이미지를 아무리 바꿔봤자 크기조절이 안된다
방법 1. support 라이브러리가 28 일때
=> BottomNavigationView XML 에서 수정가능
<android.support.design.widget.BottomNavigationView
app:itemIconSize="@dimen/_26sdp"
....
....
</android.support.design.widget.BottomNavigationView>
방법 2. support 라이브러리 27이하
<dimen name="design_bottom_navigation_height" tools:override="true">100dp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">20dp</dimen>
<dimen name="design_bottom_navigation_active_item_max_width" tools:override="true">250dp</dimen>
<dimen name="design_bottom_navigation_item_max_width" tools:override="true">200dp</dimen>
<dimen name="design_bottom_navigation_item_min_width" tools:override="true">180dp</dimen>
public boolean IsTablet() {
//화면 사이즈 종류 구하기
int screenSizeType = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
if (screenSizeType == Configuration.SCREENLAYOUT_SIZE_XLARGE || screenSizeType == Configuration.SCREENLAYOUT_SIZE_LARGE) {
return true;
}
return false;
}
if (IsTablet()) {
Log.d(TAG, "onCreate: 태블릿이다");
BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
for (int i = 0; i < menuView.getChildCount(); i++) {
final View iconView = menuView.getChildAt(i).findViewById(android.support.design.R.id.icon);
final ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams();
final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, displayMetrics);
layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 45, displayMetrics);
iconView.setLayoutParams(layoutParams);
}
}