getActionBar() returns null

前端 未结 24 1228
暗喜
暗喜 2020-11-22 13:31

I\'m having an odd problem. I am making an app with targetsdk 13.

In my main activity\'s onCreate method i call getActionBar() to setup my actionbar. T

24条回答
  •  伪装坚强ぢ
    2020-11-22 13:44

    To add to the other answers:

    Make sure you call setActionBar() or setSupportActionBar() in your onCreate() method before calling the getActionBar():

    Define some Toolbar in your activity.xml, then in the onCreate():

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(toolbar);
    // Now you can use the get methods:
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    

提交回复
热议问题