getActionBar() returns null

前端 未结 24 1243
暗喜
暗喜 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:32

    The main reason for that is using themes that are not supporting ActionBar:

    In manifest file add the following either in your target activity or application element (if you want to unify the theme over whole application)

    Examples of themes that are supporting action bar "Theme.AppCompat.Light" or "Theme.Holo.Light" ...

    android:theme="@android:style/Theme.Holo.Light"
    

    It is better to put all styles in styles.xml and use it everywhere using "@style/themName" so the previous one will be

    android:theme="@style/AppTheme"
    

    and styles.xml will have the following: