Daniel Bejan
Daniel Bejan

Reputation: 1468

getSupportActionBar() returns null and no actionbar showing in activity

I have this weird problem with the support actionbar in android.. Here's my activity:

public class TicketDetails extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.AppTheme_BlueGrey);
        setContentView(R.layout.activity_ticket_details);
        ActionBar actionBar = getSupportActionBar();//null in here 
        //some other code
   }
//some other methods
}

And my theme is defined like this:

<style name="AppTheme.BlueGrey" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/blue_grey_500</item>
        <item name="colorPrimaryDark">@color/blue_grey_700</item>
        <item name="colorAccent">@color/blue_grey_300</item>
</style>

minSdk is set to 13 and I keep getting null in there. What could be the problem? My other activities work just fine but this one has no actionbar and getSupportActionBar returns null always. Tried calling it in the onStart or onResume but still the same. Thank you!

[EDIT] This is the list with my imports:

package ga.adlabs.betticket.activities;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.widget.LinearLayout;

import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.typeface.FontAwesome;

import java.util.ArrayList;

import ga.adlabs.betticket.R;
import ga.adlabs.betticket.fragments.FragmentDataProviderTicketDetails;
import ga.adlabs.betticket.fragments.FragmentTicketDetails;
import ga.adlabs.betticket.workers.AbstractDataProvider;
import ga.adlabs.betticket.workers.DataProviderTicketList;

Upvotes: 0

Views: 3080

Answers (1)

Anggrayudi H
Anggrayudi H

Reputation: 15165

You might created the ActionBar with Material Design (also called with Toolbar). Call this code after setContentView() method:

Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar); // setting toolbar is important before calling getSupportActionBar()
ActionBar actionBar = getSupportActionBar();

Please learn more about designing the app with Material Design.

Upvotes: 1

Related Questions