我想在用户单击onBackPressed
按钮时显示AppBarLayout。我怎样才能做到这一点?
这是我的代码
片段详细信息帖子
private fun toolBarListener(view: View){
val toolbar: Toolbar = view.findViewById(R.id.tbDetailPost) as Toolbar
toolbar.setNavigationOnClickListener {
if (context is GeneralActivity){
(context as GeneralActivity).setAppBarVisible()
}else if(context is ProfileActivity){
(context as ProfileActivity).setAppBarVisible()
}else if (context is NotificationActivity){
(context as NotificationActivity).setAppBarVisible()
}
activity?.onBackPressed()
}
}
这是函数setAppBarVisible()
fun setAppBarVisible() {
appBarLayout.visibility = View.VISIBLE
}
答案 0 :(得分:0)
覆盖onBackPressed()
方法,然后像这样调用setAppBarVisible()
override fun onBackPressed() {
super.onBackPressed()
setAppBarVisible()
}