【发布时间】:2018-12-01 18:04:09
【问题描述】:
当我使用setOnNavigationItemSelectedListener 时,BottomNavigationView 会像下面的屏幕截图一样冻结涟漪效果。并且效果状态一直保持这样。
我不明白为什么?
我正在使用com.android.support:design:27.1.1
binding = DataBindingUtil
.setContentView(this, R.layout.activity_main)
bottomBar = binding?.bottomBarNavigation as BottomNavigationView
bottomBar?.setOnNavigationItemSelectedListener {
when (it.itemId) {
TabBarObject.TAB_MESSENGER -> replaceFragment(
MessengerFragment(),
TabBarObject.TAB_MESSENGER.tabName
)
...
...
}
}
private fun getTabInfo(menuItemId: Int): TabBarObject {
return when (menuItemId) {
R.id.tab_messenger -> TabBarObject.TAB_MESSENGER
...
...
else -> throw IllegalArgumentException("UNKNOWN TAB BAR TYPE")
}
}
private fun replaceFragment(fragment: Fragment, tag: String): Boolean {
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.frame_layout, fragment, tag)
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
ft.commitAllowingStateLoss()
return true
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<android.support.constraint.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".Activities.MainActivity">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottom_bar_navigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_bar_navigation"
style="@style/BottomNavigation"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottombar_tabs" />
</android.support.constraint.ConstraintLayout>
</layout>
bottombar_tabs.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/tab_messenger"
android:icon="@drawable/ic_messenger_bottom_bar"
android:title="@string/employer.app.bottombar.messenger.title" />
...
...
</menu>
【问题讨论】:
-
添加更多上下文,可能是 XML 和/或您设计中的任何自定义内容。从您发布的小 sn-p 来看,这个问题看起来很奇怪。
-
抱歉,已经完成了。
-
还有你的`style="@style/BottomNavigation"`(这很可能是问题所在)。此外,您可以将宽度设置为
match_parent,因为您不想看到它像那样(我知道您使用的是match_constraint):)
标签: android kotlin material-design bottomnavigationview