BottomNavigationView 애니메이션 제거하기
우연히 앱을 개발하다가 BottomNavigationView를 쓸 일이 왔다. 막상 적용하고 나니 애니메이션이 너무 크게 일어나기에 보기가 싫었다.(...) 이를 없애기 위해 구글링을 한 결과, 따로 메서드는 없는 것 같고 새로 클래스를 생성해서 없애주는 방법은 있었다. 해당 애니메이션은 ShiftingMode라고 불리우는것 같은데 이를 없애줄 수 있다.
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.setShiftingMode(false);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BNVHelper", "Unable to change value of shift mode", e);
}
}
}
Helper클래스를 생성해 위와 같은 소스를 추가해 준 뒤, Activity클래스에서 아래 소스를 추가해 준다.
BottomNavigationViewHelper.disableShiftMode(binding.navigation); //delete animation
나는 DataBinding을 적용했기 때문에 저렇게 뜨는 것인데, 괄호 안에는 그냥 BottomNavigationView를 지정해 주면 된다.
그럼 이상 없이 작동 되는 모습을 볼 수 있다.
'Android' 카테고리의 다른 글
Google Play Service Check(확인)하기 (0) | 2018.07.25 |
---|---|
인터넷 연결 상태 확인하기 (0) | 2018.07.23 |
Magellan(마젤란) 사용하기 (0) | 2018.07.19 |
RecyclerView에서 원하는 항목 item 제거하기 (0) | 2018.07.17 |
Google I/O Extended Seoul 참가 후기 (0) | 2018.06.12 |
댓글
이 글 공유하기
다른 글
-
Google Play Service Check(확인)하기
Google Play Service Check(확인)하기
2018.07.25 -
인터넷 연결 상태 확인하기
인터넷 연결 상태 확인하기
2018.07.23 -
Magellan(마젤란) 사용하기
Magellan(마젤란) 사용하기
2018.07.19 -
RecyclerView에서 원하는 항목 item 제거하기
RecyclerView에서 원하는 항목 item 제거하기
2018.07.17