Android - 能够在没有支持库的情况下使用AppCompatActivity

时间:2016-01-29 11:12:41

标签: android android-studio android-support-library android-appcompat android-design-library

在我的应用程序的build.gradle中,依赖项是:

compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:recyclerview-v7:22.0.0'
compile 'com.android.support:cardview-v7:22.0.0'
compile 'com.android.support:support-v13:22.0.0'
compile 'com.android.support:palette-v7:22.0.0'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:percent:22.2.0'
compile 'com.google.android.gms:play-services:7.0.0'

如果没有compile 'com.android.support:appcompat-v7:22.0.0',我仍然可以使用来自支持v7库的AppCompatActivityActionBar。任何解释背后原因的答案将不胜感激:)

2 个答案:

答案 0 :(得分:5)

您正在使用

compile 'com.android.support:design:22.2.1'

它与'com.android.support:appcompat-v7:22.2.1'

有依赖关系

这意味着如果您尚未在build.gradle中添加appcompat库,那么您的项目也会包含appcompat库,因此您可以使用AppCompatActivityActionBar

这里是pom文件:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.android.support</groupId>
  <artifactId>design</artifactId>
  <version>22.2.1</version>
  <packaging>aar</packaging>
  <dependencies>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>appcompat-v7</artifactId>
      <version>22.2.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-v4</artifactId>
      <version>22.2.1</version>
      <type>aar</type>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

您还可以使用命令gradle dependencies显示依赖关系树 您可以阅读更多info here。 (src:Using gradle to find dependency tree

答案 1 :(得分:0)

您可以使用更新的设计支持库,例如

compile 'com.android.support:design:23.1.1'

compile 'com.android.support:appcompat-v7:23.1.1'