actionbar支持v7 android

时间:2013-09-12 09:57:48

标签: android android-actionbar android-support-library

IDE :Android Studio

  1. 创建新项目
  2. 将appcompat的.jar复制到/ lib /
  3. 在项目设置中设置依赖关系
  4. 将编译“com.android.support:appcompat-v7:18.0.+”添加到build.gradle
  5. 添加以下代码:

    公共类MainActivity扩展了ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("hello");
    }
    
  6. AND ...没什么。得到下一个错误:

    "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"
    

    如何解决?我忘了做什么?

2 个答案:

答案 0 :(得分:7)

您需要安装支持存储库

  

3.选择Android支持库项目。

     

注意:如果您正在使用Android Studio进行开发,请选择并安装   改为Android支持存储库项目。   http://developer.android.com/tools/support-library/setup.html

答案 1 :(得分:0)

尝试导入库而不是复制它。

还包括:

actionBar.setDisplayShowTitleEnabled(true);
相关问题