首页 > 解决方案 > 如何在左侧操作栏上膨胀菜单

问题描述

我在顶部操作栏中有一个菜单,允许更改密码、编辑他们的个人资料和注销。我需要的是,一旦他们单击“编辑简历”选项,我想在左侧的操作栏中添加一个箭头或一个“<”,以便用户在想要退出编辑时使用“返回”选项配置文件以及在编辑时隐藏右侧菜单选项。这是我在右侧扩展菜单的代码:

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)
    }

我真的很想了解这是如何运作的背后的过程。有人能帮我吗?我也可以用箭头或“<”替换右侧的菜单,尽管我不太喜欢这个想法。

标签: androidkotlinandroid-actionbar

解决方案


这个怎么样: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,因此这似乎是执行此操作的完美方式。


推荐阅读