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
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:
<style name="AppTheme" parent="Theme.AppCompat.Light">
Hints:
"@android:style/Theme.Holo.Light.DarkActionBar"
is not supported before SDKs version 14.To allow your app to support minimum specific version of SDK you could add the following under <app>
element:
<uses-sdk android:minSdkVersion="14" />
To specify min SDK version in AndroidStudio, you could by using app's Gradle file.
android{
defaultConfig{
minSdkVersion 14
targetSdkVersion 21
}
}
ActionBar needs application or activity's Theme to have an app title. Make sure you have not styled your application or activity as Theme.NOTITLE.
<application
android:name="com.xxx.yyy"
android:debuggable="false"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/Theme.NoTitle"> // remove this line if you have this in your code
<activity
android:name="com.xxx.yyy.Activity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/Theme.NoTitle" // remove this line if you have in your code
android:windowSoftInputMode="adjustResize|stateHidden" >
I ran into this problem . I was checking for version number and enabling the action bar only if it is greater or equal to Honeycomb , but it was returning null. I found the reason and root cause was that I had disabled the Holo Theme style in style.xml under values-v11 folder.
Try extending your Activity class from ActionBarActivity. This solved it for me. Do something like the following:
public class MyActivity extends ActionBarActivity
{
. . .
In my case the class was extending only from Activity.
I faced the above issue where getActionBar()
method returns null. I was calling the getActionBar()
after setting the setContentView()
and still its returning a null
.
I resolved the issue by setting the min-sdk version in Android Manifest file that was missing initially.
<uses-sdk android:minSdkVersion="11" />
Can use getSupportActionBar()
instead of getActionBar()
method.