您的位置:首页 > 移动开发 > Android开发

android-support-v7包的添加

2015-08-03 19:39 316 查看
从网上摘抄下来的适用于Eclipse

Create a library project based on the support library code:
Make sure you have downloaded the Android Support Library using the SDK
Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
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/
.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
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.
Right-click the project and select Build Path > Configure Build Path.
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.
Uncheck Android Dependencies.
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:
In the Project Explorer, right-click your project and select Properties.
In the Library pane, click Add.
Select the library project and click OK. For example, the 
appcompat
 project should be listed as android-support-v7-appcompat.
In the properties window, click OK.

Once your project is set up with the support library, here's how to add the action bar:
Create your activity by extending 
ActionBarActivity
.
Use (or extend) one of the 
Theme.AppCompat
 themes
for your activity. For example:
<span class="tag" style="color: rgb(0, 0, 136);"><activity</span><span class="pln" style="color: rgb(0, 0, 0);"> </span><span class="atn" style="color: rgb(136, 34, 136);">android:theme</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="atv" style="color: rgb(0, 136, 0);">"@style/Theme.AppCompat.Light"</span><span class="pln" style="color: rgb(0, 0, 0);"> ... </span><span class="tag" style="color: rgb(0, 0, 136);">></span>


Now your activity includes the action bar when running on Android 2.1 (API level 7) or higher.

On API level 11 or higher

The action bar is included in all activities that use the 
Theme.Holo
 theme
(or one of its descendants), which is the default theme when either the 
targetSdkVersion
 or 
minSdkVersion
 attribute
is set to 
"11"
 or higher. If you don't want the action bar for an activity, set the activity theme to 
Theme.Holo.NoActionBar
.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  eclipse v7 v4