android 在菜单项单击时禁用底部导航栏中不需要的动画

0ve6wy6x  于 2024-01-04  发布在  Android
关注(0)|答案(1)|浏览(104)

我在Android应用程序中遇到底部导航栏NavigationBarView问题。我试图完全禁用单击菜单项时出现的动画,导致图标放大并占用更多空间。我已经尝试为图标设置特定大小,下面是布局文件(res/layout/activity_main.xml)中我的NavigationBarView的XML代码:

  1. <com.google.android.material.bottomnavigation.BottomNavigationView
  2. android:id="@+id/nav_footer"
  3. android:layout_width="match_parent"
  4. android:layout_height="@dimen/none"
  5. android:background="@drawable/back_footer_menu"
  6. app:layout_constraintBottom_toBottomOf="parent"
  7. app:layout_constraintTop_toBottomOf="@+id/end_body_h"
  8. app:menu="@menu/footer_nav_frag"
  9. app:itemIconSize="24dp" />

字符串
下面是我在MainActivity.kt中输入的内容:

  1. val bottomNavigation = findViewById<BottomNavigationView>(R.id.nav_footer)
  2. bottomNavigation.itemIconTintList = null
  3. bottomNavigation.itemTextColor = null
  4. bottomNavigation.itemRippleColor = null
  5. bottomNavigation.stateListAnimator = null
  6. bottomNavigation.setOnItemSelectedListener { menuItem ->
  7. when (menuItem.itemId) {
  8. R.id.home -> {
  9. menuItem.setIcon(R.drawable.home_degrade)
  10. bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
  11. bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
  12. bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
  13. bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
  14. true
  15. }
  16. R.id.stat -> {
  17. menuItem.setIcon(R.drawable.progress_degrade)
  18. bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
  19. bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
  20. bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
  21. bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
  22. true
  23. }
  24. R.id.calender -> {
  25. menuItem.setIcon(R.drawable.calender_degrade)
  26. bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
  27. bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
  28. bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
  29. bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
  30. true
  31. }
  32. R.id.account -> {
  33. menuItem.setIcon(R.drawable.account_degrade)
  34. bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
  35. bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
  36. bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
  37. bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
  38. true
  39. }
  40. R.id.settings -> {
  41. menuItem.setIcon(R.drawable.settings_degrade)
  42. bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
  43. bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
  44. bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
  45. bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
  46. true
  47. }
  48. else -> false
  49. }
  50. }


菜单在res/menu/footer_nav_frag.xml文件中定义。尽管我努力,动画仍然存在。是否有其他人遇到类似的问题或可以提供如何完全禁用此不良动画的指导?提前感谢您的帮助!

c2e8gylq

c2e8gylq1#

使用样式在底部导航栏在xml选择垫。

相关问题