Andrea Martinelli
Andrea Martinelli

Reputation: 312

Activity doesn't show actionbar

I joined Android Studio and Android App project a few week ago, and I'm trying to create a simple app with ActionBar options.

When I start Android Studio, following Android Dev. Training, I meet always this rendering error:

Android Studio doesn't found android.support.v7.app.ActionBarActivity (ecc...)

I resolved this error by setting a different theme. But whenever I try a new project i will do this again and again. First question: there is a way to fix this rendering problem? I meet this problem also in the MainActivity.java, where the extends ActionBarActivity is deleted with a line, telling me it is deprecated and advising me to use AppCompatActivity. Should i follow this tip?

Question number two: i read like 100 post on guys who can't show the actionbar in the activity, and I tried everything, but when I link actionbar menu with activity through:

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

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

    return super.onOptionsItemSelected(item);
}

I still can't view the menu I created on the actionbar. Some images can maybe help me to explain better my problem:

https://i.sstatic.net/5nPFx.png

And there is the layout of my activity:

http://i58.tinypic.com/oau8ed.png

As you see, there is no icon button i added and no setting button like menu layout show.

Upvotes: 3

Views: 1938

Answers (1)

Jorgesys
Jorgesys

Reputation: 126563

ActionBarActivity is now deprecated use AppCompatActivity

to avoid this error:

Android Studio doesn't found android.support.v7.app.ActionBarActivity

you have to Download the latest version of the Support Library! and then you can use

import android.support.v7.app.AppCompatActivity
    
    public class MainActivity extends AppCompatActivity{
    ...
    ...
    ...

Upvotes: 4

Related Questions