android Support Library 23.2
When talking about the Android Support Library, it is important to realize this isn’t one monolithic library, but a whole collection of libraries that 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 drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices, both VectorDrawable and AnimatedVectorDrawable are now available through two new Support Libraries support-vector-drawable and animated-vector-drawable, respectively.
html?
utm_campaign=android_launch_supportlibrary23.2_022216&utm_source=anddev&utm_medium=blog" style="text-decoration:none; color:rgb(37,138,175)">Android Studio 1.4 introduced limited support for vector drawables by generating 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 = true to your build.gradle file:
// 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, AppCompat has added a number of features to make it easy to use your new vector drawables.
Firstly, when using AppCompat with ImageView (or subclasses such as ImageButton and FloatingActionButton), you’ll be able to use the new app:srcCompat attribute to reference vector drawables (as well as any other drawable available to android: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 same setImageResource() method as before - no changes there. Using AppCompat and app:srcCompat is the most foolproof method of integrating vector drawables into your app.
You’ll find directly referencing vector drawables outside of app:srcCompat will 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, and RotateDrawable. By using this indirection, you can use vector drawables in cases such as TextView’s android:drawableLeft attribute, 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, The DayNight theme and its descendents DayNight.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 a Light and Dark theme, 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 (from UiModeManager.getNightMode()), but you can override that value with methods in AppCompatDelegate. You’ll be able to set the default across your entire app (until process restart) with the static AppCompatDelegate.setDefaultNightMode() method or retrieve an AppCompatDelegate viagetDelegate() and use setLocalNightMode() to change only the current Activity or Dialog.
When using AppCompatDelegate.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, while MODE_NIGHT_NO andMODE_NIGHT_YES forces the theme to never or always use a dark theme, respectively.
It is critical that you test your app thoroughly when using the DayNight themes as hardcoded colors can easily make for unreadable text or icons. If you are using the standard TextAppearance.AppCompat styles for your text or colors pulled from your theme such as android:textColorPrimary, you’ll find these automatically update for you.
However, if you’d like to customize any resources specifically for night mode, AppCompat reuses the night resource 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
The Design Support Library provides implementations of many patterns of material design. This release allows developers to easily add bottom sheets to their app.
By attaching a BottomSheetBehavior to a child View of a CoordinatorLayout (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 the app:behavior_peekHeight attribute (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 containing CoordinatorLayout) or the entire CoordinatorLayout is filled
- STATE_HIDDEN: disabled by default (and enabled with the app:behavior_hideable attribute), 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, or ListView/ScrollView on 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
}
});
While BottomSheetBehavior captures the persistent bottom sheet case, this release also provides aBottomSheetDialog and BottomSheetDialogFragment to fill the modal bottom sheets use case. Simply replaceAppCompatDialog or AppCompatDialogFragment with their bottom sheet equivalents to have your dialog styled as a bottom sheet.
Support v4: MediaBrowserServiceCompat
The Support v4 library serves 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 a number of unique features).
Adding onto the previously released MediaSessionCompat class to provide a solid foundation for media playback, this release adds MediaBrowserServiceCompat and MediaBrowserCompat providing 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 Auto and 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
The RecyclerView widget provides an advanced and flexible base for creating lists and grids as well as supportinganimations. This release brings an exciting new feature to the LayoutManager API: auto-measurement! This allows aRecyclerView to size itself based on the size of its contents. This means that previously unavailable scenarios, such as using WRAP_CONTENT for a dimension of the RecyclerView, 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 custom LayoutManager that does not extend one of the built in LayoutManagers, this is an opt-in API - you’ll be required to call setAutoMeasureEnabled(true) as well as make some minor changes as detailed in the Javadoc of the method.
Note that although RecyclerView animates its children, it does not animate its own bounds changes. If you would like to animate the RecyclerView bounds as they change, you can use the Transition APIs.
Custom Tabs
Custom Tabs makes 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 new addToolbarItem() method, you’ll be able to add up to currently 5 (MAX_TOOLBAR_ITEMS) actions to the bottom bar and update them with setToolbarItem() once the session has begun. Similar to the previoussetToolbarColor() method, you’ll also find a setSecondaryToolbarColor() method for customizing the background color of the bottom bar.
Leanback for Android TV
The Leanback Library gives you the tools you need to easily bring your app to Android TV with many standard components optimized for the TV experience. The GuidedStepFragment received 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 calling setButtonActions()). This makes it much easier to reach completion actions without having to scroll through the list of available GuidedActions.
Speaking of GuidedActions, there’s a number of new features to allow richer input including editable descriptions (viadescriptionEditable()), sub actions in the form of a dropdown (with subActions()), 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 at b.android.com and connect with other developers on the Android 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资产。而此前仅限于棒棒堂及更高版本号的设备,既VectorDrawable和AnimatedVectorDrawable现已通过两种新的支持库支持向量绘制和动画矢量抽拉。分别为。
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文件),每一个地方装将支持载荷向量画图资源。值得庆幸的是,应用程序兼容性已经添加了很多功能,能够非常easy地使用新的矢量画图资源。
首先。使用应用程序兼容性同当的ImageView(或子类,如ImageButton的和FloatingActionButton),你就能够使用新的应用程序:srcCompat属性来引用矢量画图资源(以及不论什么其它可用的绘制到安卓SRC):
<ImageView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
app:srcCompat = "@drawable/ic_add" />
假设你在执行时更改绘项目,你就能够使用同样的setImageResource()方法和曾经一样-没有变更。
使用应用程序兼容性和应用程序:srcCompat是矢量画图资源集成到应用的最简单的方法。
你会发现直接引用境外矢量画图资源的应用程序:srcCompat棒棒糖前将失败。然而,应用程序兼容性不支持载荷向量画图资源,当他们在还有一个容器中绘制引用。如StateListDrawable,InsetDrawable,LayerDrawable,LevelListDrawable和RotateDrawable。
通过这样的间接的。你可以使用矢量图形内容的情况下。如TextView中的 机器人:drawableLeft属性。它通常不会可以支持向量画图资源。
应用程序兼容性DayNight主题
同一时候使整个应用程序的使用矢量图形已经是一个非常大的变化,以应用程序兼容性。有加入到应用程序兼容性此版本号中的新主题:Theme.AppCompat.DayNight。
此前API 14,该DayNight主题及其后代DayNight.NoActionBar, DayNight.DarkActionBar,DayNight.Dialog,等等。
成为他们的光当量。但在API 14和更高版本号的设备,这个主题能够让应用程序能够轻松地支持一个浅而深的主题,有效地从一个光主题切换到基于它是否是“空中飞人”一个黑暗的主题。
默认情况下,不管是“空中飞人”将匹配系统值(从UiModeManager.getNightMode() ),但你可以重写与方法,该值AppCompatDelegate。你将可以在整个应用程序中设置默认值(直到进程又一次启动)与静态AppCompatDelegate.setDefaultNightMode()方法或检索通过AppCompatDelegate getDelegate() 。并使用setLocalNightMode()仅仅改变当前的活动或对话。
当使用AppCompatDelegate.MODE_NIGHT_AUTO。一天,你的最后已知位置的时间(假设您的应用程序有位置的权限)用于白天和黑夜之间自己主动切换。而MODE_NIGHT_NO和MODE_NIGHT_YES强制主题。以永不或总是使用黑暗的主题。分别。
这是您在使用的时候彻底測试你的应用程序的关键DayNight主题为硬编码的颜色能够非常easy地为不可读的文字或图标。假设您使用的是标准TextAppearance.AppCompat为您的文本或颜色从你的主题拉如样式安卓textColorPrimary。你会发现这些为你自己主动更新。
只是,假设你想专门定制不论什么资源夜间模式,应用程序兼容性重用晚上资源预选赛目录,从而能够自己定义每个你可能须要的资源。
请考虑使用标准颜色或利用在应用程序兼容性的着色支撑。以使支撑该模式easy得多。
设计支持库:底部的纸张
该设计支持库提供了非常多模式的实现材料设计。此版本号同意开发者可以轻松地加入底部的纸张到他们的应用程序。
通过附加一个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属性)。使这使得用户能够向下滑动底部片全然隐藏底层表
请记住。在你的底纸滚动容器必须支持嵌套的滚动(比如。NestedScrollView。RecyclerView或ListView控件/滚动型的API 21+)。
假设您希望收到的状态更改回调,您能够加入一个BottomSheetCallback:
//使用视图
反应状态变化
}
@覆盖
公共 无效onSlide (@NonNull 查看bottomSheet , 浮动slideOffset ) {
//反应拖动事件
}
});
尽管BottomSheetBehavior捕获持续底片的情况下,此版本号还提供了一个BottomSheetDialog和BottomSheetDialogFragment填补了模态底部的纸张使用情况。仅仅需更换AppCompatDialog或AppCompatDialogFragment与下片等值有你的风格的对话作为底片。
支持V4:MediaBrowserServiceCompat
该支持V4库用作很多支持库的基础,包含在平台(另一个较新版本号推出了很多框架功能backports中的一些独特的功能)。
加入到曾经公布的MediaSessionCompat类,以提供媒体播放了坚实的基础,这个版本号添加了MediaBrowserServiceCompat和MediaBrowserCompat提供,带来了最新的API兼容的解决方式(甚至没有在棉花糖加)回全部的API 4和更高版本号的设备。
这使得它更easy地支持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收到了显著一套与此版本号的改进。
最明显的变化可能是引入用于操作button第二列中(通过重写加入onCreateButtonActions()或调用setButtonActions() )。这使得它更easy,而无需通过可用的列表中滚动达到完毕操作GuidedActions。
说到GuidedActions,有一些新的功能。让更丰富的输入,包含可编辑的描写叙述(通过descriptionEditable() ),在下拉的形式分动作(有辅助作用() )。和一个GuidedDatePickerAction。
这些组件应该使它更easy为你的用户绝对须要时获取信息。
如今有空
Android的支持库的版本号23.2是通过您的SDK管理器和Android Studio中可用。充分利用全部的新特性以及其它bug修复从如今開始!
与往常一样。在提交错误报告b.android.com并与其它开发者交流的Android开发Google+社群。