正确设置Android Support Library

为了支持低版本的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.
上个图片吧:
正确设置Android Support Library
因为我需要使用的是支持库提供的PopupMenu,因为没有改主题结果还遇到一个java.lang.RuntimeException: Binary XML file line #17: You must supply a layout_height attribute.错误,将Actiity的主题改成:android:theme="@style/Theme.AppCompat"就可以正常工作了!  希望能够帮到遇到同样问题的童鞋!

你可能感兴趣的:(library,support,PopupMenu)