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

I am trying to use the getActionBar () method ; and I get this error: requires android.support.v7.app.ActionBar found android.app.ActionBar. How can i fix this?

+5
source share
4 answers

This error occurs because you create an object and pass it to another class reference variable. Since getActionManager provides an android.app.ActionBar object, but you are trying to assign an android.app.ActionBar class object to android.support.v7.app.ActionBar .

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

To get the action bar, you need to follow one of two approaches.

  • import android.support.v7.app.ActionBar and use the od operation getSupportActionBar() .

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

+8
source

If API levels below 11 are supported, and you will need to add the v4 support library to your project to use the action bar.

 import android.support.v7.app.ActionBar 

If only API level 11 and above is supported:

 import android.app.ActionBar 

For more information, go to white papers

+1
source

Make sure the minimum api level in the manifest file is above 11. Since the package android.support.v7.app.ActionBar is only supported at api level below 11.

So, if you want to use the ActionBar from import android.app.ActionBar , then you must have a minimum api level of 11 in the manifest file. Otherwise, you will have to add the v4 support library to your project for the action panel user from the android.support.v7.app.ActionBar package.

0
source

If running api 11 and above

 import android.app.ActionBar; 

also, if it claims to already exist, be sure to delete it

-1
source

Source: https://habr.com/ru/post/1209080/


All Articles