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

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

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


当前回答

为什么我的eclipse自动添加appcompat v7库支持 每当我创建一个新项目

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

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

其他回答

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

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

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

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

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

为什么我的eclipse自动添加appcompat v7库支持 每当我创建一个新项目

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

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

Eclipse自动创建了appcompat_v7。因为Kitkat Api本身启动,它自动添加appcompat_v7和fragment_main.xml。

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

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. Delete fragment_main.xml and Appcompat file created in your Eclipse. Edit and change your activity_main.xml like 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> In res/values/styles.xml: <resources> <style name="AppBaseTheme" parent="android:Theme.Light"> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> </style> </resources> In res/values-v11/styles.xml you have to change like these: <resources> <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> </style> </resources> In res/values-v14/styles.xml you have to change like these: <resources> <style name="AppBaseTheme" parent="android:Theme.Light"> </style> <style name="AppTheme" parent="AppBaseTheme"> </style> </resources> Change your menu/main.xml like 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> Finally change your MainActivity.java like 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); } }

同样,创建新项目时也必须这样做

如果你的目标不是2。X版本,你可以设置你的最低SDK版本为4。X,然后创建项目。不会创建Appcompat V7库。