Can use getSupportActionBar()
instead of getActionBar()
method.
import android.support.v7.app.ActionBarActivity;
public class MainActivity extends ActionBarActivity {
getSupportActionBar()
instead of getActionBar()
import android.support.v7.app.ActionBarActivity;
I recommend to use:
import android.support.v7.app.AppCompatActivity
if you are using android.support.v7.app.AppCompatActivity
public class HomeActivity extends AppCompatActivity {
Then you should be using android.support.v7.app.ActionBar
ActionBar ab = getSupportActionBar();
If you are using android.support.v4.app.FragmentActivity
public class HomeActivity extends FragmentActivity {
then you should be using android.app.ActionBar
ActionBar ab = getActionBar();
If you are using android.support.v7.app.ActionBarActivity
public class HomeActivity extends ActionBarActivity {
you should be using android.support.v7.app.ActionBar
ActionBar ab = getSupportActionBar();
You have to define window type as actionbar before activity render its view.
use
requestWindowFeature(Window.FEATURE_ACTION_BAR);
before calling setContentView() method.
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" />
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" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With