Android Support Library 23.2

When talking about the Android Support Library, it is important to realize this isn’t one monolithic library, but awhole collection of librariesthat seek to provide backward-compatible versions of APIs, as well as offer unique features without requiring the latest platform version. Version 23.2 adds a few new support libraries as well as new features to many of the existing libraries.


<iframe width="557" height="370" "="" frameborder="0" src="https://www.youtube.com/embed/7E2lNBM38IE?list=PLWz5rJ2EKKc9e0d55YHgJFHXNZbGHEXJX" allowfullscreen="" style="box-shadow: rgb(153, 153, 153) 3px 10px 18px 1px; display: block; margin-bottom: 1em; margin-left: 80px;">

Support Vector Drawables and Animated Vector Drawables

Vector drawablesallow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices, bothVectorDrawableandAnimatedVectorDrawableare now available through two new Support Librariessupport-vector-drawableandanimated-vector-drawable, respectively.

Android Studio 1.4introduced limited support for vector drawables bygenerating pngs at build time. To disable this functionality (and gain the true advantage and space savings of this Support Library),you need to addvectorDrawables.useSupportLibrary = trueto yourbuild.gradlefile:


// Gradle Plugin 2.0+  android {   defaultConfig {    vectorDrawables.useSupportLibrary = true    }  }  

You’ll note this new attribute only exists in the version 2.0 of the Gradle Plugin. If you are using Gradle 1.5 you’ll instead use


// Gradle Plugin 1.5  android {   defaultConfig {    generatedDensities = []   }   // This is handled for you by the 2.0+ Gradle Plugin   aaptOptions {    additionalParameters "--no-version-vectors"   }  }  

You’ll be able to use VectorDrawableCompat back to API 7 and AnimatedVectorDrawableCompat on all API 11 and higher devices. Due to how drawables are loaded by Android, not every place that accepts a drawable id (such as in an XML file) will support loading vector drawables. Thankfully,AppCompathas added a number of features to make it easy to use your new vector drawables.

Firstly, when using AppCompat withImageView(or subclasses such asImageButtonandFloatingActionButton), you’ll be able to use the newapp:srcCompatattribute to reference vector drawables (as well as any other drawable available toandroid:src):


<ImageView   android:layout_width="wrap_content"   android:layout_height="wrap_content"   app:srcCompat="@drawable/ic_add" />  

And if you’re changing drawables at runtime, you’ll be able to use the samesetImageResource()method as before - no changes there.Using AppCompat andapp:srcCompatis the most foolproof method of integrating vector drawables into your app.

You’ll find directly referencing vector drawables outside ofapp:srcCompatwill fail prior to Lollipop. However, AppCompat does support loading vector drawables when they are referenced in another drawable container such as aStateListDrawable,InsetDrawable,LayerDrawable,LevelListDrawable, andRotateDrawable. By using this indirection, you can use vector drawables in cases such asTextView’sandroid:drawableLeftattribute, which wouldn’t normally be able to support vector drawables.

AppCompat DayNight theme

While enabling the use of vector graphics throughout your app is already a large change to AppCompat, there’s a new theme added to AppCompat in this release:Theme.AppCompat.DayNight.


Prior to API 14, TheDayNighttheme and its descendentsDayNight.NoActionBar,DayNight.DarkActionBar, DayNight.Dialog,etc. become their Light equivalents. But on API 14 and higher devices,this theme allows apps to easily support both aLightandDarktheme, effectively switching from a Light theme to a Dark theme based on whether it is ‘night’.

By default, whether it is ‘night’ will match the system value (fromUiModeManager.getNightMode()), but you can override that value with methods inAppCompatDelegate. You’ll be able to set the default across your entire app (until process restart) with the staticAppCompatDelegate.setDefaultNightMode()method or retrieve an AppCompatDelegate viagetDelegate()and usesetLocalNightMode()to change only the currentActivityorDialog.

When usingAppCompatDelegate.MODE_NIGHT_AUTO,the time of day and your last known location (if your app has the location permissions) are used to automatically switch between day and night, whileMODE_NIGHT_NOandMODE_NIGHT_YESforces the theme to never or always use a dark theme, respectively.

It is critical that you test your app thoroughly when using theDayNightthemes as hardcoded colors can easily make for unreadable text or icons. If you are using the standardTextAppearance.AppCompatstyles for your text or colors pulled from your theme such asandroid:textColorPrimary, you’ll find these automatically update for you.

However, if you’d like to customize any resources specifically for night mode, AppCompat reuses thenightresource qualifier folder, making it possible customize every resource you may need. Please consider using the standard colors or taking advantage of the tinting support in AppCompat to make supporting this mode much easier.

Design Support Library: Bottom Sheets

TheDesign Support Libraryprovides implementations of many patterns ofmaterial design. This release allows developers to easily addbottom sheetsto their app.

By attaching aBottomSheetBehaviorto a childViewof aCoordinatorLayout(i.e., addingapp:layout_behavior="android.support.design.widget.BottomSheetBehavior"), you’ll automatically get the appropriate touch detection to transition between five state:

  • STATE_COLLAPSED:this collapsed state is the default and shows just a portion of the layout along the bottom. The height can be controlled with theapp:behavior_peekHeightattribute (defaults to 0)
  • STATE_DRAGGING:the intermediate state while the user is directly dragging the bottom sheet up or down
  • STATE_SETTLING:that brief time between when the View is released and settling into its final position
  • STATE_EXPANDED:the fully expanded state of the bottom sheet, where either the whole bottom sheet is visible (if its height is less than the containingCoordinatorLayout) or the entireCoordinatorLayoutis filled
  • STATE_HIDDEN:disabled by default (and enabled with theapp:behavior_hideableattribute), enabling this allows users to swipe down on the bottom sheet to completely hide the bottom sheet

Keep in mind that scrolling containers in your bottom sheet must support nested scrolling (for example,NestedScrollView,RecyclerView, orListView/ScrollViewon API 21+).

If you’d like to receive callbacks of state changes, you can add a BottomSheetCallback:


// The View with the BottomSheetBehavior  View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet);  BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);  behavior.setBottomSheetCallback(new BottomSheetCallback() {    @Override    public void onStateChanged(@NonNull View bottomSheet, int newState) {     // React to state change    }     @Override     public void onSlide(@NonNull View bottomSheet, float slideOffset) {     // React to dragging events   }  });  

WhileBottomSheetBehaviorcaptures thepersistent bottom sheetcase, this release also provides aBottomSheetDialogandBottomSheetDialogFragmentto fill themodal bottom sheetsuse case. Simply replaceAppCompatDialogorAppCompatDialogFragmentwith their bottom sheet equivalents to have your dialog styled as a bottom sheet.

Support v4: MediaBrowserServiceCompat

TheSupport v4 libraryserves as the foundation for much of the support libraries and includes backports of many framework features introduced in newer versions of the platform (as well anumber of unique features).

Adding onto the previously releasedMediaSessionCompatclass to provide a solid foundation for media playback, this release addsMediaBrowserServiceCompatandMediaBrowserCompatproviding a compatible solution that brings the latest APIs (even those added in Marshmallow) back to all API 4 and higher devices. This makes it much easier to supportaudio playback on Android Autoand browsing through media on Android Wear along with providing a standard interface you can use to connect your media playback service and your UI.

RecyclerView

TheRecyclerViewwidget provides an advanced and flexible base forcreating lists and gridsas well as supportinganimations. This release brings an exciting new feature to theLayoutManagerAPI: auto-measurement! This allows aRecyclerViewto size itself based on the size of its contents. This means that previously unavailable scenarios, such as usingWRAP_CONTENTfor a dimension of theRecyclerView, are now possible. You’ll find all built in LayoutManagers now support auto-measurement.

Due to this change, make sure to double check the layout parameters of your item views: previously ignored layout parameters (such as MATCH_PARENT in the scroll direction) will now be fully respected.

If you have a customLayoutManagerthat doesnotextend one of the built inLayoutManagers, this is anopt-inAPI - you’ll be required to callsetAutoMeasureEnabled(true)as well as make some minor changes as detailed in the Javadoc of the method.

Note that althoughRecyclerViewanimates its children, itdoes notanimate its own bounds changes. If you would like to animate theRecyclerViewbounds as they change, you can use theTransition APIs.

Custom Tabs

Custom Tabsmakes it possible to seamlessly transition to web content while keeping the look and feel of your app. With this release, you’ll now be able to add actions to a bottom bar for display alongside the web content.

With the newaddToolbarItem()method, you’ll be able to add up to currently 5(MAX_TOOLBAR_ITEMS)actions to the bottom bar and update them withsetToolbarItem()once the session has begun. Similar to the previoussetToolbarColor()method, you’ll also find asetSecondaryToolbarColor()method for customizing the background color of the bottom bar.

Leanback for Android TV

TheLeanback Librarygives you the tools you need to easilybring your app to Android TVwith many standard components optimized for the TV experience. TheGuidedStepFragmentreceived a significant set of improvements with this release.

The most visible change may be the introduce of a second column used for action buttons (added by overridingonCreateButtonActions()or callingsetButtonActions()). This makes it much easier to reach completion actions without having to scroll through the list of availableGuidedActions.

Speaking ofGuidedActions, there’s a number of new features to allow richer input including editable descriptions (viadescriptionEditable()), sub actions in the form of a dropdown (withsubActions()), and aGuidedDatePickerAction.


These components should make it much easier for you to get information from the user when absolutely required.

Available Now

Version 23.2 of the Android Support Library is available via your SDK Manager and Android Studio. Take advantage of all of the new features as well as additional bug fixes starting now! As always, file bug reports atb.android.comand connect with other developers on theAndroid Development Google+ community.

Android的支持库23.2

在谈到Android的支持库,它知道这不是一个整体的库是非常重要的,但图书馆的整个集合,寻求提供的API向后兼容的版本,以及提供独特的功能,而不需要最新平台版本。23.2版本增加了一些新的支持库以及新的功能,许多现有的库。


<iframe width="557" height="370" "="" frameborder="0" src="https://www.youtube.com/embed/7E2lNBM38IE?list=PLWz5rJ2EKKc9e0d55YHgJFHXNZbGHEXJX" allowfullscreen="" style="color: rgb(51, 51, 51); font-family: Roboto; font-size: 13.2px; line-height: 18.48px; box-shadow: rgb(153, 153, 153) 3px 10px 18px 1px; display: block; margin-bottom: 1em; margin-left: 80px; background-color: rgb(249, 249, 249);">

支持向量绘图资源和动画可绘制矢量

矢量绘图资源让你用一个矢量图形,定义在XML中替换多个PNG资产。而此前仅限于棒棒堂及更高版本的设备,既VectorDrawableAnimatedVectorDrawable现已通过两种新的支持库支持向量绘制动画矢量抽拉,分别为。

Android的工作室1.4通过引入矢量绘图资源有限的支持在构建时生成PNG图像。要禁用此功能(并获得这一支持库的真正优势和节省空间),你需要添加vectorDrawables.useSupportLibrary =真到你的build.gradle文件:


//摇篮插件2.0+   安卓{    defaultConfig {     vectorDrawables useSupportLibrary =      }   }  

你会注意到这个新的属性只在摇篮插件的2.0版本存在。如果您使用的是1.5摇篮,你会改用


//摇篮插件1.5   的Android {    defaultConfig {     generatedDensities =  []    }    //这是你的2.0+摇篮插件处理    aaptOptions {     additionalParameters “--no版本的载体”    }   }  

您可以使用VectorDrawableCompat回API 7 AnimatedVectorDrawableCompat所有的API 11和更高版本的设备。由于可绘是如何由Android,而不是接受绘制ID(如XML文件),每个地方装将支持载荷向量绘图资源。值得庆幸的是,应用程序兼容性已经增加了许多功能,可以很容易地使用新的矢量绘图资源。

首先,使用应用程序兼容性同当的ImageView(或子类,如ImageButton的FloatingActionButton),你就可以使用新的应用程序:srcCompat属性来引用矢量绘图资源(以及任何其他可用的绘制到安卓SRC):


<ImageView    android:layout_width = "wrap_content"    android:layout_height = "wrap_content"    app:srcCompat = "@drawable/ic_add"  />  

如果你在运行时更改绘项目,你就可以使用相同的setImageResource()方法和以前一样-没有变更。使用应用程序兼容性和应用程序:srcCompat是矢量绘图资源集成到应用的最简单的方法。

你会发现直接引用境外矢量绘图资源的应用程序:srcCompat棒棒糖前将失败。然而,应用程序兼容性不支持载荷向量绘图资源,当他们在另一个容器中绘制引用,如StateListDrawableInsetDrawableLayerDrawableLevelListDrawableRotateDrawable。通过这种间接的,你可以使用矢量图形内容的情况下,如TextView中的机器人:drawableLeft属性,它通常不会能够支持向量绘图资源。

应用程序兼容性DayNight主题

同时使整个应用程序的使用矢量图形已经是一个很大的变化,以应用程序兼容性,有添加到应用程序兼容性此版本中的新主题:Theme.AppCompat.DayNight。


此前API 14,该DayNight主题及其后代DayNight.NoActionBar,DayNight.DarkActionBar,DayNight.Dialog,等等。成为他们的光当量。但在API 14和更高版本的设备,这个主题可以让应用程序可以轻松地支持一个的主题,有效地从一个光主题切换到基于它是否是“空中飞人”一个黑暗的主题。

默认情况下,无论是“空中飞人”将匹配系统值(从UiModeManager.getNightMode()),但你可以重写与方法,该值AppCompatDelegate。你将能够在整个应用程序中设置默认值(直到进程重新启动)与静态AppCompatDelegate.setDefaultNightMode()方法或检索通过AppCompatDelegategetDelegate(),并使用setLocalNightMode()只改变当前的活动对话。

当使用AppCompatDelegate.MODE_NIGHT_AUTO,一天,你的最后已知位置的时间(如果您的应用程序有位置的权限)用于白天和黑夜之间自动切换,而MODE_NIGHT_NOMODE_NIGHT_YES强制主题,以永不或总是使用黑暗的主题,分别。

这是您在使用的时候彻底测试你的应用程序的关键DayNight主题为硬编码的颜色可以很容易地为不可读的文字或图标。如果您使用的是标准TextAppearance.AppCompat为您的文本或颜色从你的主题拉如样式安卓textColorPrimary,你会发现这些为你自动更新。

不过,如果你想专门定制任何资源夜间模式,应用程序兼容性重用晚上资源预选赛文件夹,从而可以自定义每一个你可能需要的资源。请考虑使用标准颜色或利用在应用程序兼容性的着色支撑,以使支撑该模式容易得多。

设计支持库:底部的纸张

该设计支持库提供了很多模式的实现材料设计。此版本允许开发人员能够轻松地添加底部的纸张到他们的应用程序。

通过附加一个BottomSheetBehavior到子视图一的CoordinatorLayout(即添加应用程序:layout_behavior =“android.support.design.widget.BottomSheetBehavior”),您将自动获得相应的触摸检测五州之间转换:

  • STATE_COLLAPSED:该折叠状态是默认和示出沿底部的布局只是一个部分。高度可与控制应用:behavior_peekHeight属性(默认为0)
  • STATE_DRAGGING:在用户直接拖动底部片材向上或向下的中间状态
  • STATE_SETTLING:当查看被释放和沉降到其最终位置之间短暂的时间
  • STATE_EXPANDED:所述底部片材,其中,无论是整个底片是可见的完全膨胀的状态(如果其高度小于所述含CoordinatorLayout)或整个CoordinatorLayout是填充
  • STATE_HIDDEN:默认情况下禁用(和启用应用程序:behavior_hideable属性),使这使得用户可以向下滑动底部片完全隐藏底层表

请记住,在你的底纸滚动容器必须支持嵌套的滚动(例如,NestedScrollViewRecyclerViewListView控件/滚动型的API 21+)。

如果您希望收到的状态更改回调,您可以添加一个BottomSheetCallback:


//使用视图                          反应状态变化     }      @覆盖     公共 无效onSlide @NonNull  查看bottomSheet  浮动slideOffset  {      //反应拖动事件    }   });  

虽然BottomSheetBehavior捕获持续底片的情况下,此版本还提供了一个BottomSheetDialogBottomSheetDialogFragment填补了模态底部的纸张使用情况。只需更换AppCompatDialogAppCompatDialogFragment与下片等值有你的风格的对话作为底片。

支持V4:MediaBrowserServiceCompat

该支持V4库用作许多支持库的基础,包括在平台(还有一个较新版本推出了许多框架功能backports中的一些独特的功能)。

添加到以前发布的MediaSessionCompat类,以提供媒体播放了坚实的基础,这个版本增加了MediaBrowserServiceCompatMediaBrowserCompat提供,带来了最新的API兼容的解决方案(甚至没有在棉花糖加)回所有的API 4和更高版本的设备。这使得它更容易地支持Android上的自动音频播放通过媒体和浏览的Android Wear与提供一个标准的接口,你可以用它来 ​​连接您的媒体播放服务与您一起UI。

RecyclerView

RecyclerView部件提供一个先进而灵活的基础创建列表和网格以及支持动画。这个版本带来一个激动人心的新功能将LayoutManager的API:自动测量!这允许RecyclerView根据其内容的大小尺寸本身。这意味着,先前不可用的情况,例如使用WRAP_CONTENT为的尺寸RecyclerView,现在都是可能的。你会发现所有内置的布局管理现在支持自动测量。

由于这种变化,一定要仔细检查您的项目视图的布局参数:以前被忽视的布局参数(如MATCH_PARENT的滚动方向)现在将得到充分的尊重。

如果你有一个自定义的LayoutManager,它不能扩展内置在一个布局管理,这是一个选择,在API -你会需要调用setAutoMeasureEnabled(真),以及做一些小的变化,在的的Javadoc详细方法。

注意,虽然RecyclerView动画其子,它动画其自己的边界变化。如果您想进行动画处理的RecyclerView界限,因为他们改变,您可以使用转换的API。

自定义选项卡

自定义选项卡,能够同时保持你的应用程序的外观和感觉无缝地过渡到Web内容。在这个版本中,您现在就可以行动加入底栏显示旁边的网页内容。

随着新addToolbarItem()方法,你就可以对目前5加起来(MAX_TOOLBAR_ITEMS)行动与底部栏和更新它们setToolbarItem()一旦会议已经开始。类似以前的setToolbarColor()方法,你还会发现一个setSecondaryToolbarColor()自定义底栏的背景颜色的方法。

轻松看为Android TV

在Leanback的图书馆为您提供您需要轻松的工具把你的应用程序到Android电视与电视体验优化了标准组件。该GuidedStepFragment收到了显著一套与此版本的改进。

最明显的变化可能是引入用于操作按钮第二列中(通过重写添加onCreateButtonActions()或调用setButtonActions())。这使得它更容易,而无需通过可用的列表中滚动达到完成操作GuidedActions

说到GuidedActions,有一些新的功能,让更丰富的输入,包括可编辑的描述(通过descriptionEditable()),在下拉的形式分动作(有辅助作用()),和一个GuidedDatePickerAction。


这些组件应该使它更容易为你的用户绝对需要时获取信息。

现在有空

Android的支持库的版本23.2是通过您的SDK管理器和Android Studio中可用。充分利用所有的新特性以及其他bug修复从现在开始!与往常一样,在提交错误报告b.android.com并与其他开发人员交流的Android开发Google+社群。


更多相关文章

  1. Android NDK 各版本地址大全
  2. Android应用程序资源
  3. Android重启应用程序 && 不重启应用不改变系统语言改变 Android
  4. [Android各版本特性]Android 7.0 Nougat
  5. 更新Android SDK到3.0版本时,遇到Failed to rename directory E:
  6. Android:保护自己开发的Android应用程序
  7. 第三部分:Android 应用程序接口指南---第一节:应用程序组件---第六
  8. 修改Android工程版本
  9. 2014 Android 各个版本市场占有率

随机推荐

  1. android 每周学习笔记及总结(每周更新)
  2. Android 中 WebView 使用漏洞相关介绍
  3. Dagger 2 在 Android 上的使用(一)
  4. android遇到的BUG
  5. 什么是android(What Is Android?)
  6. Android(安卓)JNI入门第五篇——基本数据
  7. Android AIDL 跨进程服务 Proxy/Stub
  8. Android如何获取多媒体文件信息
  9. Android ViewPager与WP Pivot的视图对比
  10. Anatomy of an Android Application - 剖