BlackHatSamurai
BlackHatSamurai

Reputation: 23483

Can't resolve getActionBarActivity() method

I am trying to hide the ActionBar in my Activity. I have an Activity with a Fragment, which looks like this:

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;


public class IntroActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro_activity);
        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();

            ActionBar actionBar = getSupportActionBar();<---- Error here
            actionBar.hide();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_intro, menu);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.intro_page_1, container, false);
            return rootView;
        }
    }
}

The error I get is Cannot resolve method getActionBarActivity method. I have tried extending ActionBarActivity, but when I do, I get onCreate errors, and several others.

How can I hide the action bar?

Upvotes: 0

Views: 237

Answers (3)

Dimitar Darazhanski
Dimitar Darazhanski

Reputation: 2326

It does not look like you are using the support library? If that is the case you should call getActionBar() not getSupportActionBar()

Upvotes: 1

thestrongenough
thestrongenough

Reputation: 225

use this code

ActionBar bar = getActionBar();
bar.hide();

This will solve your problem

Upvotes: 1

jimmy0251
jimmy0251

Reputation: 16463

From your imports, it looks like you're not using support library. So you should use getActionBar() instead of getSupportActionBar().

Upvotes: 1

Related Questions