繁体   English   中英

appcompat_v7和android-support-v7-appcompat之间的区别?

[英]Difference between appcompat_v7 and android-support-v7-appcompat?

人们说它们是相同的但是它们在开发者网站中所说的不同情况下使用

1 - 添加没有资源的库

To add a Support Library without resources to your application project:

Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.

2 - 使用资源添加库

To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:

Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
Right-click the library project folder and select Build Path > Configure Build Path.
In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects.

我应该何时使用appcompat_v7(自动生成项目)以及何时使用android-support-v7-appcompat?

在这种情况下,程序员需要在项目中添加资源库吗?

请用我的经验喂我

android-support-v7-appcompat.jar是一个JAR文件,只包含已编译的Java类。 appcompat_v7是一个库项目,它包含以前的JAR文件,没有实际的源代码,以及许多资源(布局,图像和c)。

appcompat-v7的特定情况下,您需要使用Library Project,因为它包含必要的UI资源。

其他库(例如v7 MediaRouter或v7 Palette)不包含这些资源,因此可以直接使用JAR文件。

请注意,差异主要适用于Eclipse(其中包含资源的库必须作为项目导入,而其他库只能放在libs文件夹中)。 使用Android Studio / gradle,这全部由构建系统处理,因此两者的过程相同。 支持库安装文档中对此进行了详细说明。

生成的appcompat_v7包含android-support-v7-appcompat库以及一些资源。 如果您让Eclipse生成主题和布局,他们将引用appcompat_v7项目中的资源,如果没有它,您的项目将无法构建。 我从来没有遇到过只需要没有资源的库的情况,但是如果你想在现有项目中加入新的支持库功能,也许你可能会这样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM