我在Android应用程序中遇到底部导航栏NavigationBarView
问题。我试图完全禁用单击菜单项时出现的动画,导致图标放大并占用更多空间。我已经尝试为图标设置特定大小,下面是布局文件(res/layout/activity_main.xml)中我的NavigationBarView
的XML代码:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_footer"
android:layout_width="match_parent"
android:layout_height="@dimen/none"
android:background="@drawable/back_footer_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/end_body_h"
app:menu="@menu/footer_nav_frag"
app:itemIconSize="24dp" />
字符串
下面是我在MainActivity.kt中输入的内容:
val bottomNavigation = findViewById<BottomNavigationView>(R.id.nav_footer)
bottomNavigation.itemIconTintList = null
bottomNavigation.itemTextColor = null
bottomNavigation.itemRippleColor = null
bottomNavigation.stateListAnimator = null
bottomNavigation.setOnItemSelectedListener { menuItem ->
when (menuItem.itemId) {
R.id.home -> {
menuItem.setIcon(R.drawable.home_degrade)
bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
true
}
R.id.stat -> {
menuItem.setIcon(R.drawable.progress_degrade)
bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
true
}
R.id.calender -> {
menuItem.setIcon(R.drawable.calender_degrade)
bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
true
}
R.id.account -> {
menuItem.setIcon(R.drawable.account_degrade)
bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
bottomNavigation.menu.findItem(R.id.settings)?.setIcon(R.drawable.settings)
true
}
R.id.settings -> {
menuItem.setIcon(R.drawable.settings_degrade)
bottomNavigation.menu.findItem(R.id.stat)?.setIcon(R.drawable.progress)
bottomNavigation.menu.findItem(R.id.calender)?.setIcon(R.drawable.calender_white)
bottomNavigation.menu.findItem(R.id.account)?.setIcon(R.drawable.account)
bottomNavigation.menu.findItem(R.id.home)?.setIcon(R.drawable.home_white)
true
}
else -> false
}
}
型
菜单在res/menu/footer_nav_frag.xml文件中定义。尽管我努力,动画仍然存在。是否有其他人遇到类似的问题或可以提供如何完全禁用此不良动画的指导?提前感谢您的帮助!
1条答案
按热度按时间c2e8gylq1#
使用样式在底部导航栏在xml选择垫。