昨天在ADT Manager里更新了一些组件,结果ADT不支持。索性直接下载了最新的ADT。但是发现无论创建什么类型的应用(无论支持的最低API是多少,或者是不是用模板),都会在创建应用的同时创建一个appcompat_v7的类库,然后用创建的应用引用它。
这个类库是用来向以前基本兼容的,比如让3.0之前的版本支持ActionBar。但Google为什么每次都要引用这个呢,令人费解,现在2.x的份额已经降到很低了。难道是为了推广自家的appcompat类库,让用户摆脱ActionBarSherlock吗。
在*上看到有人问同样的问题,有人给出了回答(戳这里),这里整理一下:
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。
步骤一:右击项目,选择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.
步骤二:在Library窗口,选中 "appcompat_v7_NNN",选择Remove,然后点OK。
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.、
步骤三:在res/values/styles.xml中,把AppBaseTheme的parent从
Theme.AppCompat.Light
改成 @android:style/Theme.Light。
res/values-v11/styles.xml中
, change the parent
of AppBaseTheme
from Theme.AppCompat.Light
to @android:style/Theme.Holo.Light
.
rest/values-v14/styles.xml
change the
parent
of AppBaseTheme
from Theme.AppCompat.Light.DarkActionBar
to @android:style/Theme.Holo.Light.DarkActionBar
.
(把各个版本的style都从AppCompat改成系统默认的Theme,但是这样3.0之前的版本就不支持ActionBar了。)
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.
步骤四:删掉res/menu/main/xml中的xmlns:app="http://schemas.android.com/apk/res-auto"和app:showAsAction="never"元素。
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).
步骤五:在activity中,比如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.
这个时候除了Project>clean,appcompat应该差不多从你的项目里移除了。