Android 为什么每当我创建新项目时 Eclipse 都会自动添加 appcompat v7 库支持?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22261288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:43:49  来源:igfitidea点击:

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

androideclipseandroid-appcompat

提问by Talha Qamar

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

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

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

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

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

如何在没有appcompat库的情况下创建一个简单的项目?仅供参考,我已经下载了最新版本的 ADT,最近更新了所有内容。我正在使用 Window 7 x64。

Enter image description here

在此处输入图片说明

采纳答案by Halim Qarroum

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 toolsincluded in Eclipse through the Android Development Tools (ADT)integrate them by default.

这就是为什么Eclipse 中包含的Android代码模板工具Android Development Tools (ADT)默认通过集成它们的原因。

I noted that you target API 15in 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 APIwhich appeard on API 11(Android 3.0 Honeycomb)on a device that runs an older version of this system.

我注意到您API 15在示例中定位,但您的包所需的最小 SDK 是API 10,为此,兼容性库可以提供大量向后兼容的 API。例如,可以在运行旧版本系统的设备Fragment API上使用API 11(Android 3.0 Honeycomb)上出现的 。

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

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

回答by songhir

Create a new Android Application Projectand uncheckCreate activityin step two (Configure project).

在第二步(配置项目)中创建一个新的Android Application Project取消选中Create activity

回答by Adam Stelmaszczyk

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,其中Action Bar默认开启,你的最小支持SDK设置为10。Action Bar出现在11,所以你需要一个支持库,Eclipse为你添加了它。参考。

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

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

回答by Steve

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

Eclipse将自动创建奇巧的API appcompat_v7.Because推出它本身会自动添加appcompat_v7fragment_main.xml

Best ways to solve these:

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

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

  2. Delete fragment_main.xmland Appcompatfile created in your Eclipse.

  3. Edit and change your activity_main.xmllike these:

    <?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:

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

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

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

    <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.javalike these:

    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);
    
    }
    
    }
    
  1. 首先在项目中,Right click->properties->Android.在那里你可以看到red marked appcompat放置在Reference. 单击它并删除它。然后在 中勾选正确的目标名称Project Build Target

  2. 删除在Eclipse 中创建的fragment_main.xmlAppcompat文件。

  3. 像这样编辑和更改您的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. res/values/styles.xml 中:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
    
        </style>
    
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
    
        </style>
    
    </resources>
    
  5. res/values-v11/styles.xml你必须像这样改变:

    <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        </style>
    
    </resources>
    
  6. res/values-v14/styles.xml你必须像这样改变:

      <resources>
    
        <style name="AppBaseTheme" parent="android:Theme.Light">
        </style>
    
        <style name="AppTheme" parent="AppBaseTheme">
        </style>
    
    </resources>
    
  7. 像这样更改你的menu/main.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. 最后像这样改变你的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

同样,你必须这样做才能创建一个新项目

回答by Ahmad

It's included because your minimum SDK version is set to 10. The ActionBarwas 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 版本范围内看起来更加一致。

回答by Swapnil

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.x 版本,您可以设置 4.x 的最低 sdk 版本,然后创建项目。不会创建 Appcompat V7 库。

回答by Lê Quang Duy

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_xappear again. My ADT's version is v22.6.2-1085508.
I'm sorry if my English is bad.

我是 Android 新手,当我创建新的 Android 应用程序项目时,总是会创建项目 appcompat_v7,这让我很不舒服。

这只是四处走走。选择 Project Properties -> Android 然后在 Library 框中删除 appcompat_v7_x 并添加 appcompat_v7。现在您可以删除 appcompat_v7_x。

在创建项目向导中取消选中创建活动不起作用,因为通过向导创建活动时appcompat_v7_x再次出现。我的 ADT 版本是v22.6.2-1085508
如果我的英语不好,我很抱歉。

回答by nobjta_9x_tq

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。

回答by b1nary.atr0phy

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 级别 11)中添加的,但它们也在支持库中提供,以便与 Android 2.1(API 级别 7)及更高版本兼容。

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

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

Example of ActionBar on Froyo

Froyo 上的 ActionBar 示例

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

有关该主题的简化说明和教程,请参阅http://hmkcode.com/add-actionbar-to-android-2-3-x/

回答by Jeevan

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

我注意到在使用 ADT 22.6.2 版本创建新的 android 项目时创建了“appcompat”库,即使 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.xml 中找到app:showAsAction="never"来自支持库的项目。

  • If the app is targeted at android version 11 and above then one can change this attribute to android:showAsActionin menu's main.xml
  • Also the default theme set could be "Theme.AppCompat.Light.DarkActionBar" as shown below (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"

  • 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.
  • 如果应用程序针对 android 版本 11 及更高版本,则可以将此属性更改为android:showAsAction菜单的 main.xml
  • 默认主题集也可以是“Theme.AppCompat.Light.DarkActionBar”,如下所示(styles.xml)

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

    在这种情况下,style.xml 中的父主题必须更改为“android:style/Theme.Holo.Light.DarkActionBar”

  • 除此之外,如果在MainActivity.java的代码中引用了支持库中的Fragment,Fragment Manager,这些必须适当地更改为SDK的Fragment,FragmentManager。