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.
You should:
AppCompatActivitygetSupportActionBar()instead ofgetActionBar()Theme.AppCompat.Lightfor all devices (remove the material theme in v21)