Android BottomNavigationView在滚动时隐藏,但在片段更改时不显示
我有一个BottomNavigationView,当视图滚动到底部时隐藏,当视图滚动到顶部时返回 当底部导航视图被隐藏且我更改时,我的问题是 我无法在中显示BottomNavigationView的片段 任何帮助都是可观的 下面是我的仪表盘活动代码。ktAndroid BottomNavigationView在滚动时隐藏,但在片段更改时不显示,android,bottomnavigationview,Android,Bottomnavigationview,我有一个BottomNavigationView,当视图滚动到底部时隐藏,当视图滚动到顶部时返回 当底部导航视图被隐藏且我更改时,我的问题是 我无法在中显示BottomNavigationView的片段 任何帮助都是可观的 下面是我的仪表盘活动代码。kt 更新至最新的支持库版本28.0.0-alpha1,只需向BottomNavigationView添加一个属性 <BottomNavigationView .... .... app:layout_behavior="@strin
更新至最新的支持库版本28.0.0-alpha1,只需向BottomNavigationView添加一个属性
<BottomNavigationView
....
....
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"/>
注意:-请参见此处您的活动代码在哪里?@PratikButani问题中添加的活动代码可能会有帮助:@PratikButani很抱歉,这对我来说不是预期的结果。我希望在片段更改时,我的底部导航视图可见性可见,因为当前正在发生的情况是,当片段滚动时BottomNavigationView正在隐藏,当我以编程方式更改片段时,BottomNavigationView不会显示在任何地方,我希望您能正确回答我的问题。行为部分已经存在,问题是如何在片段更改时自动显示我的底部导航视图他已经在使用:
app:layout_behavior=“@string/hide_bottom_view_on_scroll_behavior”
检查XMLbottomNavigation.setBehaviorTranslationEnabled(false);bottomNavigation.setTranslucentNavigationEnabled(false);使用这个,我在我的代码中使用永久隐藏
class DashboardActivity : BaseActivity(), EditProfileFragment.RefreshView, AddPatientFragment.NavigateView {
override fun navigateView() {
toDashboard()
}
override fun refreshView() {
val f: Fragment? = supportFragmentManager.findFragmentById(R.id.frame_container)
if (f != null && f is ProfileFragment) {
f.refreshView()
supportActionBar?.title = PROFILE
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dashboard)
initializeToolBar()
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
toDashboard()
}
/**
* Initialization of ToolBar
*/
private fun initializeToolBar() {
val toolbar: Toolbar = findViewById(R.id.toolbar)
setSupportActionBar(toolbar)
if (supportActionBar != null) {
supportActionBar!!.setDisplayShowHomeEnabled(true)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
}
}
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
when (item.itemId) {
R.id.navigation_home -> {
toDashboard()
return@OnNavigationItemSelectedListener true
}
R.id.navigation_medicine -> {
toMedicines()
return@OnNavigationItemSelectedListener true
}
R.id.navigation_add_patient -> {
toAddPatient()
return@OnNavigationItemSelectedListener true
}
R.id.navigation_profile -> {
toProfile()
return@OnNavigationItemSelectedListener true
}
}
false
}
private fun toProfile() {
toggleToolBar(false)
// navigation.selectedItemId = R.id.navigation_profile
navigation.labelVisibilityMode = View.VISIBLE
replaceFragment(ProfileFragment::class.java, PROFILE, false, null, R.id.frame_container)
}
private fun toAddPatient() {
toggleToolBar(false)
// navigation.selectedItemId = R.id.navigation_add_patient
navigation.labelVisibilityMode = View.VISIBLE
replaceFragment(AddPatientFragment::class.java, ADD_PATIENT, false, null, R.id.frame_container)
}
private fun toMedicines() {
toggleToolBar(false)
// navigation.selectedItemId = R.id.navigation_medicine
navigation.labelVisibilityMode = View.VISIBLE
replaceFragment(MedicineFragment::class.java, MEDICINE, false, null, R.id.frame_container)
}
private fun toDashboard() {
toggleToolBar(false)
navigation.labelVisibilityMode = View.VISIBLE
// navigation.selectedItemId = R.id.navigation_home
replaceFragment(HomeFragment::class.java, HOME, false, null, R.id.frame_container)
}
private fun toggleToolBar(value: Boolean) {
supportActionBar?.setDisplayHomeAsUpEnabled(value)
supportActionBar?.setDisplayShowHomeEnabled(value)
}
}
<BottomNavigationView
....
....
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"/>