正确设置Android Support Library

本文详细介绍了如何在Eclipse中正确配置Android支持库的过程,包括下载支持库、创建库项目及添加所需的JAR文件等步骤,并解决了在配置过程中可能遇到的一些常见错误。
为了支持低版本的Android,一般都要使用到Google提供的支持类库,但今天在设置支持类库的时候,总是遇到错误,弄了大半天才搞定,做个记录,以供遇到同样问题的童鞋参考. 首先需要下载支持库,使用SDK Manager即可,位置在<sdk>/extras/android/support/...。下载好后,需要将你需要的类库copy到你当前工程的同一个目录下,一般在workspace下,不然在添加引用类库的时候会得到一个红叉,完整的请参考文档,路径为:docs/tools/support-library/setup.html.我这儿只截取在eclipse下的设置.
Create a library project based on the support library code:
  1. Make sure you have downloaded the Android Support Library using the SDK Manager.
  2. Create a library project and ensure the required JAR files are included in the project's build path:
    1. Select File > Import.
    2. Select Existing Android Code Into Workspace and click Next.
    3. Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
    4. Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    5. In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
    6. Right-click the project and select Build Path > Configure Build Path.
    7. In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
    8. Uncheck Android Dependencies.
    9. Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects. Add the library to your application project:
  1. In the Project Explorer, right-click your project and select Properties.
  2. In the Library pane, click Add.
  3. Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
  4. In the properties window, click OK.
上个图片吧:
因为我需要使用的是支持库提供的PopupMenu,因为没有改主题结果还遇到一个java.lang.RuntimeException: Binary XML file line #17: You must supply a layout_height attribute.错误,将Actiity的主题改成:android:theme="@style/Theme.AppCompat"就可以正常工作了!  希望能够帮到遇到同样问题的童鞋!

转载于:https://my.oschina.net/javaTechLover/blog/341637

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值