当我创建一个新项目时,为什么Eclipse会自动添加appcompat v7库支持?

时间:2023-01-24 17:02:27

Why does Eclipse automatically add appcompat v7 library support whenever I create a new project?

当我创建一个新项目时,为什么Eclipse会自动添加appcompat v7库支持?

I am creating a simple project whose MainActivity should extend Activity, but it does not. Eclipse automatically adds action bar support.

我正在创建一个简单的项目,它的主要活动应该扩展活动,但它没有。Eclipse自动添加操作栏支持。

How do I create a simple project without the appcompat library? FYI, I have downloaded the latest version of ADT with everything updated recently. I am using Window 7 x64.

如何在没有appcompat库的情况下创建一个简单的项目?我已经下载了最新版本的ADT,最近更新了一切。我使用的是Window 7 x64。

当我创建一个新项目时,为什么Eclipse会自动添加appcompat v7库支持?

10 个解决方案

#1


105  

As stated in Android's Support Library Overview, it is considered good practice to include the support library by default because of the large diversity of devices and the fragmentation that exists between the different versions of Android (and thus, of the provided APIs).

正如在Android的支持库概述中所述,由于设备的多样性以及不同版本的Android(因此,提供的api)之间存在的碎片,所以将支持库包含在默认库中被认为是很好的做法。

This is the reason why Android code templates tools included in Eclipse through the Android Development Tools (ADT) integrate them by default.

这就是为什么Android代码模板工具在Eclipse中通过Android开发工具(ADT)在默认情况下集成它们的原因。

I noted that you target API 15 in your sample, but the miminum required SDK for your package is API 10, for which the compatibility libraries can provide a tremendous amount of backward compatible APIs. An example would be the ability of using the Fragment API which appeard on API 11 (Android 3.0 Honeycomb) on a device that runs an older version of this system.

我注意到在您的示例中您的目标API是15,但是miminum所需要的软件包是API 10,因此兼容库可以提供大量向后兼容的API。一个例子是使用在运行旧版本系统的设备上的API 11 (Android 3.0 Honeycomb)上出现的片段API的能力。

It is also to be noted that you can deactivate automatic inclusion of the Support Library by default.

还需要注意的是,默认情况下,您可以禁用支持库的自动包含。

#2


59  

Create a new Android Application Project and uncheck Create activity in step two (Configure project).

创建一个新的Android应用程序项目,并在步骤2(配置项目)中取消检查创建活动。

#3


22  

Why my eclipse automatically adds appcompat v7 library support whenever i create a new project

为什么每次创建新项目时,eclipse都会自动添加appcompat v7库支持?

Because your target SDK is set to 15, in which the Action Bar is on by default and your minimum supported SDK is set to 10. Action Bar come out in 11, so you need a support library, Eclipse adds it for you. Reference.

因为您的目标SDK设置为15,其中操作栏默认为on,而您的最小支持SDK设置为10。Action Bar在11中出现,所以您需要一个支持库,Eclipse为您添加了它。参考。

You can configure project libraries in the build path of project properties.

您可以在项目属性的构建路径中配置项目库。

#4


18  

Eclipse automatically created the appcompat_v7.Because of Kitkat Api launched itself it adds automatically appcompat_v7 and fragment_main.xml.

Eclipse会自动创建appcompat_v7。由于Kitkat Api的推出,它自动添加了appcompat_v7和fragment_main.xml。

Best ways to solve these:

解决这些问题的最佳方法:

  1. Firstly in project,Right click->properties->Android.There you can see the red marked appcompat placed in Reference. Click that and Remove it.Then Tick the right target name in Project Build Target.

    首先在项目,右键- >属性- > Android。在那里您可以看到红色标记的appcompat放在引用。单击并删除它。然后在项目构建目标中勾选正确的目标名称。

  2. Delete fragment_main.xml and Appcompat file created in your Eclipse.

    删除fragment_main。在Eclipse中创建的xml和Appcompat文件。

  3. Edit and change your activity_main.xml like these:

    编辑并更改activity_main。xml这样的:

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    
    </RelativeLayout>
    
  4. In res/values/styles.xml:

    在res /价值/ styles.xml:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
    
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
    
        </style>
    
    </resources>
    
  5. In res/values-v11/styles.xml you have to change like these:

    在res / values-v11 /风格。xml必须改变如下:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        </style>
    
    </resources>
    
  6. In res/values-v14/styles.xml you have to change like these:

    在res / values-v14 /风格。xml必须改变如下:

      <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
        </style>
    
        <style name="AppTheme" parent="AppBaseTheme">
        </style>
    
    </resources>
    
  7. Change your menu/main.xml like these:

    改变你的菜单/主要。xml这样的:

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item
            android:id="@+id/action_settings"
            android:orderInCategory="100"
            android:showAsAction="never"
            android:title="@string/action_settings"/>
    
    </menu>
    
  8. Finally change your MainActivity.java like these:

    最终改变你的MainActivity。java这样的:

    import android.app.Activity;
    import android.os.Bundle;
    
    
    public class MainActivity extends Activity {
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    }
    
    }
    

LikeWise you have to do it for creating a new project

同样地,你必须为创建一个新项目而做。

#5


8  

It's included because your minimum SDK version is set to 10. The ActionBar was introduced in API 11. Eclipse adds it automatically so your app can look more consistent throughout the spectrum of all android versions you are supporting.

它包括因为您的最小SDK版本设置为10。ActionBar是在API 11中引入的。Eclipse会自动添加它,这样你的应用程序就可以在你支持的所有android版本中看起来更加一致。

#6


4  

If you are not targeting 2.x versions you can set your minimum sdk version of 4.x and then create project. Appcompat V7 lib wont be created.

如果你的目标不是2。您可以设置您的最小sdk版本4。然后创建项目。将不会创建Appcompat V7 lib。

#7


4  

I'm new with Android and the project appcompat_v7 always be created when I create new Android application project makes me so uncomfortable.

This is just a walk around. Choose Project Properties -> Android then at Library box just remove appcompat_v7_x and add appcompat_v7. Now you can delete appcompat_v7_x.

Uncheck Create Activity in create project wizard doesn't work, because when creating activity by wizard the appcompat_v7_x appear again. My ADT's version is v22.6.2-1085508.
I'm sorry if my English is bad.

我是Android的新手,当我创建新的Android应用程序项目时,总是会创建appcompat_v7,这让我很不舒服。这只是随便走走。选择项目属性-> Android,然后在库框中删除appcompat_v7_x并添加appcompat_v7。现在可以删除appcompat_v7_x。在Create project向导中,Uncheck创建活动不起作用,因为当通过向导创建活动时,appcompat_v7_x再次出现。我的ADT的版本是v22.6.2-1085508。如果我的英语不好,我很抱歉。

#8


3  

Sorry with my English, When you create a new android project, you should choose api of high level, for example: from api 17 to api 21, It will not have appcompat and very easy to share project. If you did it with lower API, you just edit in Android Manifest to have upper API :), after that, you can delete Appcompat V7.

抱歉,我的英语,当您创建一个新的android项目时,您应该选择高级的api,例如:从api 17到api 21,它不会有appcompat,并且很容易共享项目。如果您使用的是低级API,您只需在Android Manifest中编辑,以获得上API:),之后,您可以删除Appcompat V7。

#9


2  

According to http://developer.android.com/guide/topics/ui/actionbar.html

据http://developer.android.com/guide/topics/ui/actionbar.html

The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.

ActionBar API最初是在Android 3.0 (API level 11)中添加的,但是它们也可以在支持库中使用,以与Android 2.1 (API级别7)和以上版本兼容。

In short, that auto-generated project you're seeing modularizes the process of adding the ActionBar to APIs 7-10.

简而言之,您看到的自动生成的项目模块化了将ActionBar添加到api 7-10的过程。

当我创建一个新项目时,为什么Eclipse会自动添加appcompat v7库支持?

See http://hmkcode.com/add-actionbar-to-android-2-3-x/ for a simplified explanation and tutorial on the topic.

请参阅http://hmkcode.com/add- actionbarto -android-2-3-x/以获得关于该主题的简单解释和教程。

#10


0  

I noticed creation of 'appcompat' library while creating new android project with ADT 22.6.2 version, even when the minSDK was set to 11 and targetSDK was set 19

我注意到创建“appcompat”库的同时,创建了带有ADT 22.6.2版本的新android项目,即使minSDK设置为11,targetSDK也设置为19。

This was happening because, in the new project template android is using some attributes that are from the support library. For instance if a new project was created with actionbar then in the menu's main.xml one could find app:showAsAction="never" which is from support library.

这是因为,在新的项目模板中,android使用了一些来自支持库的属性。例如,如果在菜单的main中使用actionbar创建了一个新项目。xml one可以找到应用程序:showAsAction=“never”,它来自支持库。

  • If the app is targeted at android version 11 and above then one can change this attribute to android:showAsAction in menu's main.xml
  • 如果这个应用程序是针对android版本11的,那么你可以把这个属性改成android:在菜单的main.xml中显示动作。
  • Also the default theme set could be "Theme.AppCompat.Light.DarkActionBar" as shown below (styles.xml)

    默认的主题集也可以是“Theme.AppCompat.Light”。如下所示(styles.xml)

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
           <!-- API 14 theme customizations can go here. -->
       </style> 
    

    In this case the parent theme in style.xml has to be changed to "android:style/Theme.Holo.Light.DarkActionBar"

    在这种情况下,样式的父主题。xml必须改为“android:style/ theme.o . light.darkactionbar”

  • In addition to this if reference to Fragment,Fragments Manager from support library was made in the code of MainActivity.java, these have to appropriately changed to Fragment, FragmentManager of the SDK.
  • 除了这一点,如果引用片段,支持库中的片段管理器是在MainActivity的代码中进行的。java,这些必须适当地更改为SDK的碎片管理器。

#1


105  

As stated in Android's Support Library Overview, it is considered good practice to include the support library by default because of the large diversity of devices and the fragmentation that exists between the different versions of Android (and thus, of the provided APIs).

正如在Android的支持库概述中所述,由于设备的多样性以及不同版本的Android(因此,提供的api)之间存在的碎片,所以将支持库包含在默认库中被认为是很好的做法。

This is the reason why Android code templates tools included in Eclipse through the Android Development Tools (ADT) integrate them by default.

这就是为什么Android代码模板工具在Eclipse中通过Android开发工具(ADT)在默认情况下集成它们的原因。

I noted that you target API 15 in your sample, but the miminum required SDK for your package is API 10, for which the compatibility libraries can provide a tremendous amount of backward compatible APIs. An example would be the ability of using the Fragment API which appeard on API 11 (Android 3.0 Honeycomb) on a device that runs an older version of this system.

我注意到在您的示例中您的目标API是15,但是miminum所需要的软件包是API 10,因此兼容库可以提供大量向后兼容的API。一个例子是使用在运行旧版本系统的设备上的API 11 (Android 3.0 Honeycomb)上出现的片段API的能力。

It is also to be noted that you can deactivate automatic inclusion of the Support Library by default.

还需要注意的是,默认情况下,您可以禁用支持库的自动包含。

#2


59  

Create a new Android Application Project and uncheck Create activity in step two (Configure project).

创建一个新的Android应用程序项目,并在步骤2(配置项目)中取消检查创建活动。

#3


22  

Why my eclipse automatically adds appcompat v7 library support whenever i create a new project

为什么每次创建新项目时,eclipse都会自动添加appcompat v7库支持?

Because your target SDK is set to 15, in which the Action Bar is on by default and your minimum supported SDK is set to 10. Action Bar come out in 11, so you need a support library, Eclipse adds it for you. Reference.

因为您的目标SDK设置为15,其中操作栏默认为on,而您的最小支持SDK设置为10。Action Bar在11中出现,所以您需要一个支持库,Eclipse为您添加了它。参考。

You can configure project libraries in the build path of project properties.

您可以在项目属性的构建路径中配置项目库。

#4


18  

Eclipse automatically created the appcompat_v7.Because of Kitkat Api launched itself it adds automatically appcompat_v7 and fragment_main.xml.

Eclipse会自动创建appcompat_v7。由于Kitkat Api的推出,它自动添加了appcompat_v7和fragment_main.xml。

Best ways to solve these:

解决这些问题的最佳方法:

  1. Firstly in project,Right click->properties->Android.There you can see the red marked appcompat placed in Reference. Click that and Remove it.Then Tick the right target name in Project Build Target.

    首先在项目,右键- >属性- > Android。在那里您可以看到红色标记的appcompat放在引用。单击并删除它。然后在项目构建目标中勾选正确的目标名称。

  2. Delete fragment_main.xml and Appcompat file created in your Eclipse.

    删除fragment_main。在Eclipse中创建的xml和Appcompat文件。

  3. Edit and change your activity_main.xml like these:

    编辑并更改activity_main。xml这样的:

    <?xml version="1.0" encoding="utf-8"?>
    
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/hello_world" />
    
    </RelativeLayout>
    
  4. In res/values/styles.xml:

    在res /价值/ styles.xml:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
    
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
    
        </style>
    
    </resources>
    
  5. In res/values-v11/styles.xml you have to change like these:

    在res / values-v11 /风格。xml必须改变如下:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        </style>
    
    </resources>
    
  6. In res/values-v14/styles.xml you have to change like these:

    在res / values-v14 /风格。xml必须改变如下:

      <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
        </style>
    
        <style name="AppTheme" parent="AppBaseTheme">
        </style>
    
    </resources>
    
  7. Change your menu/main.xml like these:

    改变你的菜单/主要。xml这样的:

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item
            android:id="@+id/action_settings"
            android:orderInCategory="100"
            android:showAsAction="never"
            android:title="@string/action_settings"/>
    
    </menu>
    
  8. Finally change your MainActivity.java like these:

    最终改变你的MainActivity。java这样的:

    import android.app.Activity;
    import android.os.Bundle;
    
    
    public class MainActivity extends Activity {
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    }
    
    }
    

LikeWise you have to do it for creating a new project

同样地,你必须为创建一个新项目而做。

#5


8  

It's included because your minimum SDK version is set to 10. The ActionBar was introduced in API 11. Eclipse adds it automatically so your app can look more consistent throughout the spectrum of all android versions you are supporting.

它包括因为您的最小SDK版本设置为10。ActionBar是在API 11中引入的。Eclipse会自动添加它,这样你的应用程序就可以在你支持的所有android版本中看起来更加一致。

#6


4  

If you are not targeting 2.x versions you can set your minimum sdk version of 4.x and then create project. Appcompat V7 lib wont be created.

如果你的目标不是2。您可以设置您的最小sdk版本4。然后创建项目。将不会创建Appcompat V7 lib。

#7


4  

I'm new with Android and the project appcompat_v7 always be created when I create new Android application project makes me so uncomfortable.

This is just a walk around. Choose Project Properties -> Android then at Library box just remove appcompat_v7_x and add appcompat_v7. Now you can delete appcompat_v7_x.

Uncheck Create Activity in create project wizard doesn't work, because when creating activity by wizard the appcompat_v7_x appear again. My ADT's version is v22.6.2-1085508.
I'm sorry if my English is bad.

我是Android的新手,当我创建新的Android应用程序项目时,总是会创建appcompat_v7,这让我很不舒服。这只是随便走走。选择项目属性-> Android,然后在库框中删除appcompat_v7_x并添加appcompat_v7。现在可以删除appcompat_v7_x。在Create project向导中,Uncheck创建活动不起作用,因为当通过向导创建活动时,appcompat_v7_x再次出现。我的ADT的版本是v22.6.2-1085508。如果我的英语不好,我很抱歉。

#8


3  

Sorry with my English, When you create a new android project, you should choose api of high level, for example: from api 17 to api 21, It will not have appcompat and very easy to share project. If you did it with lower API, you just edit in Android Manifest to have upper API :), after that, you can delete Appcompat V7.

抱歉,我的英语,当您创建一个新的android项目时,您应该选择高级的api,例如:从api 17到api 21,它不会有appcompat,并且很容易共享项目。如果您使用的是低级API,您只需在Android Manifest中编辑,以获得上API:),之后,您可以删除Appcompat V7。

#9


2  

According to http://developer.android.com/guide/topics/ui/actionbar.html

据http://developer.android.com/guide/topics/ui/actionbar.html

The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.

ActionBar API最初是在Android 3.0 (API level 11)中添加的,但是它们也可以在支持库中使用,以与Android 2.1 (API级别7)和以上版本兼容。

In short, that auto-generated project you're seeing modularizes the process of adding the ActionBar to APIs 7-10.

简而言之,您看到的自动生成的项目模块化了将ActionBar添加到api 7-10的过程。

当我创建一个新项目时,为什么Eclipse会自动添加appcompat v7库支持?

See http://hmkcode.com/add-actionbar-to-android-2-3-x/ for a simplified explanation and tutorial on the topic.

请参阅http://hmkcode.com/add- actionbarto -android-2-3-x/以获得关于该主题的简单解释和教程。

#10


0  

I noticed creation of 'appcompat' library while creating new android project with ADT 22.6.2 version, even when the minSDK was set to 11 and targetSDK was set 19

我注意到创建“appcompat”库的同时,创建了带有ADT 22.6.2版本的新android项目,即使minSDK设置为11,targetSDK也设置为19。

This was happening because, in the new project template android is using some attributes that are from the support library. For instance if a new project was created with actionbar then in the menu's main.xml one could find app:showAsAction="never" which is from support library.

这是因为,在新的项目模板中,android使用了一些来自支持库的属性。例如,如果在菜单的main中使用actionbar创建了一个新项目。xml one可以找到应用程序:showAsAction=“never”,它来自支持库。

  • If the app is targeted at android version 11 and above then one can change this attribute to android:showAsAction in menu's main.xml
  • 如果这个应用程序是针对android版本11的,那么你可以把这个属性改成android:在菜单的main.xml中显示动作。
  • Also the default theme set could be "Theme.AppCompat.Light.DarkActionBar" as shown below (styles.xml)

    默认的主题集也可以是“Theme.AppCompat.Light”。如下所示(styles.xml)

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
           <!-- API 14 theme customizations can go here. -->
       </style> 
    

    In this case the parent theme in style.xml has to be changed to "android:style/Theme.Holo.Light.DarkActionBar"

    在这种情况下,样式的父主题。xml必须改为“android:style/ theme.o . light.darkactionbar”

  • In addition to this if reference to Fragment,Fragments Manager from support library was made in the code of MainActivity.java, these have to appropriately changed to Fragment, FragmentManager of the SDK.
  • 除了这一点,如果引用片段,支持库中的片段管理器是在MainActivity的代码中进行的。java,这些必须适当地更改为SDK的碎片管理器。