Android - How to hide menu option for current fragment

前端 未结 6 1544
执笔经年
执笔经年 2021-01-12 20:39

I have an ActionBar activity with a FrameLayout and a menu. when the user clicks the menu item I replace the fragment with the relevant new fragment. However, I cannot see a

6条回答
  •  既然无缘
    2021-01-12 21:36

    // create Boolean variable in the main activity
    private var menuvisibile:  Boolean = true
    
    // while navigating fragments set the menuvisibile value and use it 
    // variable as part of the return statement
    invalidateOptionsMenu()
    menuvisibile = false
    
    override fun onCreateOptionsMenu(menu: Menu?): Boolean 
        {
            val menuInflater  = menuInflater
            menuInflater.inflate(R.menu.notification,menu)
            return menuvisibile
        }
    

    working well for me.

提交回复
热议问题