为什么每当我创建一个新项目时,Eclipse都会自动添加appcompat v7库支持?
我正在创建一个简单的项目,它的MainActivity应该扩展Activity,但它没有。Eclipse自动添加操作栏支持。
我如何创建一个简单的项目没有appcompat库?供您参考,我已经下载了最新版本的ADT,最近更新了所有内容。我使用的是windows7 x64。
为什么每当我创建一个新项目时,Eclipse都会自动添加appcompat v7库支持?
我正在创建一个简单的项目,它的MainActivity应该扩展Activity,但它没有。Eclipse自动添加操作栏支持。
我如何创建一个简单的项目没有appcompat库?供您参考,我已经下载了最新版本的ADT,最近更新了所有内容。我使用的是windows7 x64。
当前回答
正如Android的支持库概述中所述,默认情况下包含支持库被认为是一个很好的实践,因为设备的多样性很大,并且存在于不同版本的Android(以及所提供的api)之间。
这就是为什么Eclipse中包含的Android代码模板工具通过Android开发工具(ADT)默认集成它们的原因。
我注意到在示例中您的目标是API 15,但是包所需的最小SDK是API 10,为此兼容性库可以提供大量向后兼容的API。一个例子就是在运行该系统旧版本的设备上使用API 11 (Android 3.0 Honeycomb)上出现的Fragment API。
还需要注意的是,您可以在默认情况下禁用支持库的自动包含。
其他回答
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); } }
同样,创建新项目时也必须这样做
创建一个新的Android应用程序项目,取消第二步(配置项目)中的创建活动。
我注意到在创建ADT 22.6.2版本的新android项目时创建了“appcompat”库,即使minSDK设置为11,targetSDK设置为19
这是因为,在新的项目模板中,android正在使用一些来自支持库的属性。例如,如果一个新项目是用actionbar创建的,那么在菜单的main.xml中,你可以从支持库中找到app: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 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.
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.
为什么我的eclipse自动添加appcompat v7库支持 每当我创建一个新项目
因为您的目标SDK设置为15,其中操作栏默认开启,您的最小支持SDK设置为10。操作栏在11年推出,所以你需要一个支持库,Eclipse为你添加了它。参考。
您可以在项目属性的构建路径中配置项目库。