onCreateOptionsMenu is never called

后端 未结 11 1090
有刺的猬
有刺的猬 2020-12-13 03:13

I am having some trouble getting an options menu working in Android. I have built apps before, and they all worked fine, but now the menu just doesn\'t pop up.

The c

11条回答
  •  青春惊慌失措
    2020-12-13 04:12

    I had a similar issue, but a different solution I am sharing with the community (as it took me one hour to understand what was happening):

        abstract class BaseActivity : AppCompatActivity{
          override fun onCreate(savedInstanceState: Bundle?) {
          setSupportActionBar(my_toolbar)
          }
        }
        class MyActivity : BaseActivity{
            // TODO : some good stuff
        }
    

    where my_toolbar is an object created in my xml file through dataBinding.

    The issue looks the same, no toolbar appear, no call to onCreateOptionsMenu.

    My solution was to promote this code to the child class and not to that basic, as my_toolbar is only initialized as the child class is built.

提交回复
热议问题