ActionBar(ActionBarCompat)教程(part1预备知识及初次上手).pptx_第1页
ActionBar(ActionBarCompat)教程(part1预备知识及初次上手).pptx_第2页
ActionBar(ActionBarCompat)教程(part1预备知识及初次上手).pptx_第3页
ActionBar(ActionBarCompat)教程(part1预备知识及初次上手).pptx_第4页
ActionBar(ActionBarCompat)教程(part1预备知识及初次上手).pptx_第5页
已阅读5页,还剩19页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

ActionBarCompat Tutorial Part 1-Prepare and Setup,http:/www.mobiletuts.me M,2019/5/26,Mobiletuts.me ,Action Bar,2019/5/26,Mobiletuts.me ,The action bar is a window feature that identifies the user location, and provides user actions and navigation modes. Using the action bar offers your users a familiar interface across applications that the system gracefully adapts for different screen configurations.,Figure 1. An action bar that includes the 1 app icon, 2 two action items, and 3 action overflow.,The action bar provides several key functions: Provides a dedicated space for giving your app an identity and indicating the users location in the app. Makes important actions prominent and accessible in a predictable way (such as Search). Supports consistent navigation and view switching within apps (with tabs or drop-down lists).,ActionBarActivity or Activity?,If you want to set title , logo, navigation modes for an ActionBar, you need to get a reference to ActionBar. With sdk level higher than 11 (=11), you can directly call getActionBar() in an Activity to fetch a reference of ActionBar which you can configure. For sdk level lower than 11 (=10), however, getActionBar is not supported in an Activity.,2019/5/26,Mobiletuts.me ,ActionBarActivity or Activity?,Google Android team released a new backward-compatible Action Bar implementation called ActionBarCompat thats part of the Support Library r18 during I/O 2013 . The ActionBarCompat APIs let you build the essential Action Bar design pattern into your app, with broad compatibility back to Android 2.1 (sdk7). ActionBarActivity (android.support.v7.app.ActionBarActivity) and ActionBar (android.support.v7.app.ActionBar) was introduced within ActionBarCompat, which can be used essentially as same as Activity with ActionBar features in sdk levels higher than 11.,2019/5/26,Mobiletuts.me ,ActionBarActivity for Backward Compatibility,Therefore use ActionBarActivity if you need to use ActionBar while supporting sdk level lower than 11.,2019/5/26,Mobiletuts.me ,Get Started with ActionBarCompat,ActionBarCompat is a new API in the Android Support Library that allows you to add an Action Bar to applications targeting minSdkVersion 7 or greater. The API and integration have been designed to closely mirror the existing framework APIs, giving you an easy migration path for your existing apps.,2019/5/26,Mobiletuts.me ,Add ActionBarCompat as a project dependency,1. Android Studio or Eclipse+ADT go to Tools-Android-SDK Manager,2. Check if the Android Support Library (revision 18) has been installed.,The version of Android support library ( Revision 18 ) is released with a new library called appcompat under the package android.support.v7.The new library facilitates users to implement action bar back up to Android 2.1 ( API Level 7 ) .,2019/5/26,Mobiletuts.me ,Adding ActionBarCompat support library,Eclipse Make sure you have downloaded the Android Support Library using the SDK Manager. Create a libs/ directory in the root of your application project. Copy the JAR files from your Android SDK installation directory /extras/android/support/v7/appcompat/libs/android-support-v4.jar /extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar into your applications project libs/ directory. Right click the JAR file and select Build Path Add to Build Path. Android Studio Make sure you have downloaded the Android Support Repository using the SDK Manager. Open the build.gradle file for your application. Add the support library to the dependencies section. For example, to add the v7 appcompat library, add the following lines: dependencies compile com.android.support:appcompat-v7:18.0.0 ,2019/5/26,Mobiletuts.me ,Create New Android Project,2019/5/26,Mobiletuts.me ,Create New Android Project,2019/5/26,Mobiletuts.me ,Dependency,The Gradle build script dependency identifier for this library is as follows: com.android.support:appcompat-v7:18.0.0+ This dependency notation specifies the release version 18.0.0 or higher.,2019/5/26,Mobiletuts.me ,When using default Activity,2019/5/26,Mobiletuts.me ,Default Activity support ActionBar on level higher than API 11,2019/5/26,Mobiletuts.me ,Running on API17,Use ActionBarActivity for Backward Compatibility,2019/5/26,Mobiletuts.me ,Using ActionBarActivity instead of Activity,Done? Not yet, if you compile and run now, you will run into fata error caused by theme setting.,Error Caused by Theme Setting,2019/5/26,Mobiletuts.me ,This is cause by theme setting. When using ActionBarCompat, you can only use a Theme.AppCompat theme or its descendant (for customized theme).,Update Style Resources,2019/5/26,Mobiletuts.me ,The first things to update are your Activity themes so they use a Theme.AppCompat theme. If youre currently using one of the Theme.Holo themes then just replace this with the related Theme.AppCompat theme. For instance if you have the following in your AndroidManifest.xml: You would change it to: ,UseTheme.AppCompat theme or its descendant,Update Style Resources,2019/5/26,Mobiletuts.me ,UseTheme.AppCompat theme or its descendant,If you dont want to change your activities theme setting one by one, you can change the theme setting for application in AndroidManifest.xml: ,Becareful with values-v11/14,When you update the style resource files, do update all the styles.xml in values folder and the possible values-v11 and values-v14 folder. Cause your app may load styles.xml file in values-v1X folder according to target Android API level!,2019/5/26,Mobiletuts.me ,Try again, it works now!,2019/5/26,Mobiletuts.me ,Running on API17,Add More Actions on Action Bar,2019/5/26,Mobiletuts.me ,In the following sections, I will show how to add Actions such as Search to Action Bar.,You can download these icons which you can use for Actions from Download the Action Bar Icon Pack Then copy the icons you need to drawable folders. Here I copied 2_action_search.png files to drawable-hdpi, drawable-xhdpi and drawable-mdpi folders.,Structure of Action Bar Icon Pack,2019/5/26

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论