Android get Support Action Bar always returns NULL

android, android-support-library, nullpointerexception

Solution

Using `android:windowNoTitle` with `true` is hiding your `ActionBar`

Problem

I'm using the support library v7 on a certain project. I'm trying to instantiate the support action bar like this: ``` ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.top_action_bar); actionBar.setDisplayShowCustomEnabled(true); actionBar.setHomeButtonEnabled(true); ``` Everything works fine on Android devices with API lvl below 11. However, while trying to run the same code on newer devices, like a Samsung Galaxy S4 with Android 4+, getSupportActionBar() always returns null, causing the expected crash. I'm using this style file: ``` <style name="my_style" parent="@style/Theme.AppCompat.Light"> <item name="android:actionBarStyle">@style/my_style_ab</item> <item name="android:windowNoTitle">true</item> </style> <style name="my_style_ab" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="android:height">70dp</item> </style> ``` Any hints on what may be wrong? I think it has something to do with the style, or maybe I just can't use the support ActionBar on API lvl above 11. Thanks in advance.

Original source