Java 如何删除支持库 (appcompat_v7) [Eclipse]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22769016/
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
How to remove support library (appcompat_v7) [Eclipse]
提问by AlphaCode
I've updated my eclipse and ADT Plugin to the latest version recently and recognised some big changes. Whenever I create a new Android Application Project there appears a new appcompat_v7 library which wasn't present before and also a fragment_main.xml . Why is that? Why is the activity_main.xml file not preferred for activity layout directly anymore and why appcompat library is now included in every project ? I tried to remove eclipse/adt/sdk many times and remove the support library from sdk manager but got no result ! I realize it has something to do with actionbar but the problem is that whenever I create a new project a red exclamation mark shows up on both project's file and appcompat_v7 file and this prevents me from compiling/running the application or even sometimes appcompat_v7 file doesn't create and the only thing I get is damaged code here's a picture :http://i.stack.imgur.com/XJMfW.png
我最近将我的 eclipse 和 ADT 插件更新到了最新版本,并发现了一些重大变化。每当我创建一个新的 Android 应用程序项目时,都会出现一个以前不存在的新 appcompat_v7 库和一个 fragment_main.xml 。这是为什么?为什么 activity_main.xml 文件不再直接用于活动布局,为什么 appcompat 库现在包含在每个项目中?我多次尝试删除 eclipse/adt/sdk 并从 sdk 管理器中删除支持库,但没有结果!我意识到它与操作栏有关,但问题是每当我创建一个新项目时,项目文件和 appcompat_v7 文件上都会出现一个红色感叹号,这会阻止我编译/运行应用程序,甚至有时 appcompat_v7 文件不会http://i.stack.imgur.com/XJMfW.png
so how can I remove this dependency and thanks
那么我该如何删除这种依赖,谢谢
采纳答案by CommonsWare
Why is that?
这是为什么?
Because Google engineers added that stuff to the new-activity templates, for at least the "BlankActivity".
因为谷歌工程师将这些东西添加到新活动模板中,至少是“BlankActivity”。
Why is the activity_main.xml file not preferred for activity layout directly anymore
为什么 activity_main.xml 文件不再直接用于活动布局
You are certainly welcome to use activity_main.xml
for whatever you want. It so happens that Google's current templates want you to use fragments. Google's templates are just templates. One can argue -- and I have, vehemently -- that a "BlankActivity" template should not be doing what it is doing. However, beyond that, it is just a template.
当然欢迎您随意使用activity_main.xml
。碰巧的是,Google 当前的模板希望您使用片段。Google 的模板只是模板。有人可能会争辩说——我强烈认为——“BlankActivity”模板不应该做它正在做的事情。然而,除此之外,它只是一个模板。
why appcompat library is now included in every project ?
为什么 appcompat 库现在包含在每个项目中?
Presumably, they wanted to start you off with a consistent action bar, even on older API levels.
据推测,他们希望以一致的操作栏开始,即使是在较旧的 API 级别。
I realize it has something to do with actionbar but the problem is that whenever I create a new project a red exclamation mark shows up on both project's file and appcompat_v7 file and this prevents me from compiling/running the application or even sometimes appcompat_v7 file doesn't create and the only thing I get is damaged code
我意识到它与操作栏有关,但问题是每当我创建一个新项目时,项目文件和 appcompat_v7 文件上都会出现一个红色感叹号,这会阻止我编译/运行应用程序,甚至有时 appcompat_v7 文件不会t 创建,我唯一得到的是损坏的代码
I reported this issuea week or so ago.
我一周前报告了这个问题。
so how can I remove this dependency
那么我怎样才能删除这种依赖
Step #1: Right-click over the project name in the Package Explorer, and choose Properties. Click on Android in the list of property categories on the left, and scroll down on the right to the bottom:
第 1 步:在 Package Explorer 中右键单击项目名称,然后选择 Properties。单击左侧属性类别列表中的 Android,然后从右侧向下滚动到底部:
Step #2: In the list of attached library projects that you will now see in the properties dialog, you may see an entry akin to the "appcompat_v7_6" one that you see in the above screenshot. Your last digit will differ, and it may be that yours has a red X instead of a green checkmark. Regardless, if there is an entry for "appcompat_v7_NNN" in the list, click on it, then click the Remove button to the right of the list. Then, click the OK button to close up the dialog.
第 2 步:在您现在将在属性对话框中看到的附加库项目列表中,您可能会看到一个类似于您在上面屏幕截图中看到的“appcompat_v7_6”条目。您的最后一位数字会有所不同,可能是您的数字带有红色 X 而不是绿色复选标记。无论如何,如果列表中有“appcompat_v7_NNN”条目,请单击它,然后单击列表右侧的“删除”按钮。然后,单击“确定”按钮关闭对话框。
Step #3: In res/values/styles.xml
, change the parent of AppBaseTheme
from Theme.AppCompat.Light
to @android:style/Theme.Light
. In res/values-v11/styles.xml
, change the parent of AppBaseTheme
from Theme.AppCompat.Light
to @android:style/Theme.Holo.Light
. In rest/values-v14/styles.xml
change the parent of AppBaseTheme
from Theme.AppCompat.Light.DarkActionBar
to @android:style/Theme.Holo.Light.DarkActionBar
. Note that these values assume that you chose the default "Light theme with dark action bar" when you created the project -- you will need to make slight adjustments to those instructions for anything else.
第 3 步:在 中res/values/styles.xml
,将AppBaseTheme
from的父级更改Theme.AppCompat.Light
为@android:style/Theme.Light
。在res/values-v11/styles.xml
中,父亲改为AppBaseTheme
从Theme.AppCompat.Light
到@android:style/Theme.Holo.Light
。在rest/values-v14/styles.xml
变化的父母AppBaseTheme
从Theme.AppCompat.Light.DarkActionBar
到@android:style/Theme.Holo.Light.DarkActionBar
。请注意,这些值假定您在创建项目时选择了默认的“带有深色操作栏的浅色主题”——您需要对其他任何说明对这些说明进行轻微调整。
Step #4: In res/menu/main/xml
, remove xmlns:app="http://schemas.android.com/apk/res-auto"
from the root <menu>
element and the app:showAsAction="never"
attribute from the <item>
element.
第 4 步:在 中res/menu/main/xml
,xmlns:app="http://schemas.android.com/apk/res-auto"
从根<menu>
元素和元素中删除app:showAsAction="never"
属性<item>
。
Step #5: In your activity (e.g., MainActivity
), change the parent class of the activity to something other than ActionBarActivity
-- FragmentActivity
would be a good choice, to minimize the number of other changes you will have to make immediately. Also, clean your imports (e.g., Ctrl-Shift-O).
第 5 步:在您的活动中(例如,MainActivity
),将活动的父类更改为除ActionBarActivity
-- 之外的其他内容,这FragmentActivity
将是一个不错的选择,以最大限度地减少您必须立即进行的其他更改的数量。此外,清理您的导入(例如,Ctrl-Shift-O)。
At this point, other than perhaps cleaning your project (Project > Clean from the main menu), the appcompat
stuff should be ripped out of a project created using the "BlankActivity" template and with a "Navigation Type" of "None". Other templates, or navigation options on the "BlankActivity" template, will probably require more work.
在这一点上,除了可能清理您的项目(主菜单中的项目 > 清理)之外,appcompat
应该从使用“BlankActivity”模板创建的项目中删除这些内容,并且“导航类型”为“无”。其他模板或“BlankActivity”模板上的导航选项可能需要更多工作。
回答by Steve
Best ways to solve these:
解决这些问题的最佳方法:
Firstly in project,
Right click->properties->Android
.There you can see thered marked appcompat
placed inReference
. Click that and Remove it.Delete fragment_main.xmland Appcompatfile created in your Eclipse.
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>
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.xmlyou have to change like these:
<resources> <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> </style> </resources>
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>
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>
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); } }
首先在项目中,
Right click->properties->Android
.在那里你可以看到red marked appcompat
放置在Reference
. 单击它并删除它。删除在Eclipse 中创建的fragment_main.xml和Appcompat文件。
像这样编辑和更改您的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>
在res/values/styles.xml 中:
<resources> <style name="AppBaseTheme" parent="android:Theme.Light"> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> </style> </resources>
在res/values-v11/styles.xml你必须像这样改变:
<resources> <style name="AppBaseTheme" parent="android:Theme.Holo.Light"> </style> </resources>
在res/values-v14/styles.xml你必须像这样改变:
<resources> <style name="AppBaseTheme" parent="android:Theme.Light"> </style> <style name="AppTheme" parent="AppBaseTheme"> </style> </resources>
像这样更改你的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>
最后像这样改变你的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
同样,你必须这样做才能创建一个新项目