Support for actionbar v7 android

IDE : Android Studio

  • Create a new project
  • Copy .jar appcompat using / lib /
  • Set dependencies in project settings
  • Add compilation "com.android.support:appcompat-v7:18.0.+" to build .gradle
  • Add the following code:

    public class MainActivity extends ActionBarActivity {

    @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("hello"); } 

And nothing. Get the following error:

 "Gradle: A problem occurred configuring project ':MyApplication'. > Failed to notify project evaluation listener. > Could not resolve all dependencies for configuration ':MyApplication:_DebugCompile'. > Could not find any version that matches com.android.support:appcompat-v7:18.0.+. Required by: MyApplicationProject:MyApplication:unspecified" 

How to fix? What did I forget to do?

+4
source share
2 answers

you need to install support repository

3. Select the Android Support Libraries item.

Note. If you are using Android Studio, select and install the Android Support Repository Element. http://developer.android.com/tools/support-library/setup.html

+7
source

Try importing the library, not copying it.

Also include:

 actionBar.setDisplayShowTitleEnabled(true); 
0
source

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


All Articles