Reputation: 121
Having issue with ActionBar NullPointerException based on different API. All my activities extend Activity
.
This is my code:
Gradle
minSdkVersion 17
targetSdkVersion 23
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
Styles:
<style name="AppTheme" parent="Theme.AppCompat.Light">
Styles (values-v21):
<style name="AppTheme" parent="android:Theme.Material.Light">
Activity:
ActionBar actionBar = getActionBar();
assert actionBar != null;
actionBar.hide();
It works fine on API23 but give NullPointerException
on lower.
Read other similar question, tried with ActionBarActivity
(deprecated), AppCompatActivity
, SupportActionBar
but I am not able to let it works on different API.
Any suggestions? Any help would be much appreciated. Thanks in advance.
Upvotes: 0
Views: 71
Reputation: 363835
You should:
AppCompatActivity
getSupportActionBar()
instead of getActionBar()
Theme.AppCompat.Light
for all devices (remove the material theme in v21)Upvotes: 1