Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: required android.support.v7.app.ActionBar found android.app.ActionBar

I am trying to use the getActionBar(); method and I receive this error: required android.support.v7.app.ActionBar found android.app.ActionBar . How can I correct this?

like image 606
Juvie22 Avatar asked Dec 15 '14 10:12

Juvie22


People also ask

Where is ActionBar in Android?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button. In general an ActionBar consists of the following four components: App Icon: App branding logo or icon will be displayed here.

What is getSupportActionBar?

To use the ActionBar utility methods, call the activity's getSupportActionBar() method. This method returns a reference to an appcompat ActionBar object. Once you have that reference, you can call any of the ActionBar methods to adjust the app bar.

How to enable action bar in android studio?

setDisplayUseLogoEnabled(true); getSupportActionBar(). setLogo(R. drawable. ic__actionbar); // Set up the action bar.

What is a support action bar Android studio?

In Android applications, ActionBar is the element present at the top of the activity screen. It is a salient feature of a mobile application that has a consistent presence over all its activities. It provides a visual structure to the app and contains some of the frequently used elements for the users.


1 Answers

This error is occurring because you are creating an object and passing it to a different class reference variable. Because getActionManager gives the object of android.app.ActionBar but you are trying to assign android.app.ActionBar class object to android.support.v7.app.ActionBar.

But both these classes provide the same functionality. android.support.v7.app.ActionBar Class is used when our uses-sdk min version is less the api 11. to get the object of ActionBar below api 11 we need android.support.v7.app.ActionBar class object.

To get Action bar you need to follow one of two approaches.

  1. import android.support.v7.app.ActionBar and use getSupportActionBar() method od activity.

  2. go to AndroidManifest.xml file and change <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" /> and import android.app.ActionBar and use getActionBar()

like image 63
Umesh Kumar Saraswat Avatar answered Sep 22 '22 11:09

Umesh Kumar Saraswat