android - 如何在左侧操作栏上膨胀菜单
问题描述
我在顶部操作栏中有一个菜单,允许更改密码、编辑他们的个人资料和注销。我需要的是,一旦他们单击“编辑简历”选项,我想在左侧的操作栏中添加一个箭头或一个“<”,以便用户在想要退出编辑时使用“返回”选项配置文件以及在编辑时隐藏右侧菜单选项。这是我在右侧扩展菜单的代码:
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
inflater!!.inflate(R.menu.profiletoolbar, menu)
super.onCreateOptionsMenu(menu, inflater)
}
//get the actionbar selction when pressed
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
R.id.userLogout -> {
FirebaseAuth.getInstance().signOut()
val i = Intent(context, Login::class.java)
startActivity(i)
true
}
R.id.editBio -> {
editProfileBio()
true
}
else -> super.onOptionsItemSelected(item)
}
我真的很想了解这是如何运作的背后的过程。有人能帮我吗?我也可以用箭头或“<”替换右侧的菜单,尽管我不太喜欢这个想法。
解决方案
这个怎么样:setDisplayHomeAsUpEnabled()
R.id.editBio -> {
editProfileBio()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
true
}
按下时处理:
override fun onBackPressed() {
super.onBackPressed()
// do your stuff when pressed the back Button
}
我也可以用箭头或“<”替换右侧的菜单,尽管我不太喜欢这个主意。
也不喜欢这种想法。Button
通过单击时启用后退editbio
,您将可以访问当前菜单并且也会有后退Button
,因此这似乎是执行此操作的完美方式。
推荐阅读
- javascript - 使用 React 组件的最佳方式
- android - 使用 SharedPreference 保存后 onResume 上的变量值错误
- asp.net - Kentico 基于声明的身份验证 SAML 2.0
- jenkins - 在哪里可以找到在 Jenkins 中更改工作区路径位置的选项?
- python - 使用 pyInstaller 到闪存驱动器后指定 PyPDF2 的文件路径
- javascript - 将 JavaScript TemplateLiteral 转换为 python 字典
- javascript - HTML5:恢复播放的视频
- c++ - 内联 SSE2 程序集因数据更改而崩溃
- docker - 如何创建正确的 .lando.yml 自定义文件?
- javascript - 在 react-select 输入更改状态后,React 不会重新渲染 ComponentDidUpdate