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?
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.
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.
setDisplayUseLogoEnabled(true); getSupportActionBar(). setLogo(R. drawable. ic__actionbar); // Set up the action bar.
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.
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.
import android.support.v7.app.ActionBar
and use getSupportActionBar()
method od activity.
go to AndroidManifest.xml file and change <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" />
and import android.app.ActionBar
and use getActionBar()
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