getAction Bar gives null pointer exception

后端 未结 2 2077
半阙折子戏
半阙折子戏 2020-12-22 04:03

i want to work with action bar in android. for this i use

getActionBar().setHomeButtonEnabled(true);

below the SetContentView . but is gi

相关标签:
2条回答
  • 2020-12-22 04:33

    getActionBar() will return null for pre Honeycomb devices.

    If you are targeting Android v2.3 to 4.2 try out ActionBarSherlock.

    0 讨论(0)
  • 2020-12-22 04:38

    If your activity does not have a title bar the method getActionBar() can return null.

    You have two options to fix this:

    1- Add getWindow().requestFeature(Window.FEATURE_ACTION_BAR); before setContentView

    2- In your Manifest specify a Theme that supports ActionBar

    Also make sure that you are targeting the right android version e.g. <uses-sdk android:minSdkVersion="11" />

    0 讨论(0)
提交回复
热议问题