Android Design Support Library概览
尊重劳动成果。转载请注明出处:http://blog.csdn.net/growth58/article/details/47972467
关注新浪微博:@于卫国
邮箱:yuweiguocn@gmail.com
简单介绍
在Google I/O 2015大会中,Google为Android开发人员介绍了Design Support Library。
这个library能够让开发人员非常easy地实现很多其他Material Design概念到他们的应用中,由于非常多关键元素是不可用的在原来的框架外。
首先就是非常易于使用,Design Support Library向下兼容到API 7。Design Support Library能够引入到你的Androidproject中通过导入Gradle依赖。
compile 'com.android.support:design:22.2.0'
视觉组件
在Design支持库中有两个主要类别的工具:
- 视觉组件
- 动作组件
我们先看看有哪些新的视觉组件能够应用到你的App上。
Material Text Input
EditText自从最開始就已经在Android中了,而且使用非常简单,他们一直没有什么改变。使用Design Support Library。Google已经介绍了新的包括容器叫作TextInputLayout。
这个新的view加入功能到标准的EditText上。比如支持让你的用户界面弹出错误消息和动画提示。
正如以下的代码所看到的。TextInputLayout 能够包括在你的布局文件里包裹一个标准的EditText。
" />
" data-snippet-id="ext.258d3706ad9b2a815c28e952db131b6d" data-snippet-saved="false" data-codota-status="done"><android.support.design.widget.TextInputLayout
android:id="@+id/textinput"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="What is your name?
" />
</android.support.design.widget.TextInputLayout>
Gianluca Segato 会带着你学习TextInputLayout 组件的使用在教程中。
Floating Action Buttons
在Material Design 应用中最占优势的用户界面组件之中的一个就是Floating Action Buttons。
自从他们的介绍后,开发人员不得不从头開始创建这些button或者是从非常多第三方设计的类库特别是这些button相关的选择一个。
使用Design 支持库,floating action buttons能够包括在一个布局中而且挂靠在屏幕的一部分用简单几行代码。每一个button都能够用icons和colors非常easy地进行自己定义。能够使用两个sizes 。standard (56dp) 和 mini (40dp)。最大的优势之中的一个是Google已经支持这些button作为他们的设计演变。
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="@drawable/ic_fab" />
导航组件
当ViewPager 和DrawerLayout 组件通过v4 support library可用时,Google已经对其进行了扩展通过提供两个新的相关的部件。第一个是官方版本号经常使用的ViewPagerIndicator library由Jake Wharton开发称为TabLayout。第二个是NavigationView。提供drawer header的支持。
TabLayout
TabLayout组件能够用代码使用addTab方法手动加入内容。
看看以下的样例。
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
另外,你能够将TabLayout和ViewPager组件进行关联。通过调用setupWithViewPager()能够完毕,使用ViewPager作为參数。
这是还有一种方式切换ViewPager的页面。应该注意的是getPageTitle()须要被重写当使用TabLayout和ViewPager时给每一个Tab一个合适的名称。
NavigationView
NavigationView是一个新的部件继承了DrawerLayout的功能。
开发人员使用这个组件能非常easy地加入头布局到drawer 和标记已选择的部分。
除此之外。它如今能够通过菜单资源文件非常简单地创建sections和subsections在drawer 中。
一个NavigationView须要和一个DrawerLayout进行关联在XML文件里。
" data-snippet-id="ext.6f5b303a1955708a167669e03d1e1b90" data-snippet-saved="false" data-codota-status="done"><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/content"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/drawer_view"/>
</android.support.v4.widget.DrawerLayout>
增强的Toasts
Toast消息成为Android中基本的功能已经多年。一个新的用户界面部件叫作Snackbar可用于提供类似功能但改善了外观。Snackbar 不仅能给用户提示短时间的信息。它还支持一个动作加入到上下文中基于你的应用的功能而且能够使用手势滑掉使其消失。
Snackbar 比Toast功能有所增强,使用它须要注意的是须要创建一个能够被用来找到应用显示的最底部的View。
Snackbar.make( view, "Action", Snackbar.LENGTH_LONG )
.setAction("Action!", new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("App", "Action!");
}
} )
.show();
动作组件
一个用户界面特效和动画在Material Design中是非常重要的。为了促进这个,Googlen已经公布了多个常见用例的组件在Design支持库中。Kerry Perez-Huanca将会在教程中带着大家学习Design支持库中的这方面的组件。
Reactive Views
你可能已经注意到了在之前样例中的FloatingActionButton会在Snackbar出现的时候向上移动。这是用一个新的部件叫作CoordinatorLayout完毕的。用它包裹的view应该给其他view留出空间。
改善Quick Return and Toolbars
非常多开发人员询问用最简单的方式显示一个视差图片作用于高速返回设计模式。随着用户上下滑动而出现或消失。
你能够在Play Store的应用列表看到这个效果。为了让开发人员实现这个功能不用写大量冗余代码,Google公布了CollapsingToolBarLayout 和AppBarLayout views。在这些部件里使用不同的选项,开发人员能固定views在屏幕的顶部或特定的位置当这些views应该随着用户滑动显示时。
总结
Design 支持库带来了大量期待已久的工具在Android上。当它和AppCompat 库配合使用时。它变得非常easy地加入Material Design到应用上而且保持向下兼容。
能够在Google官方相关的应用上找到这些新组件是如何工作的非常多样例,CheeseSquare,Tuts+将会继续提供深入教程在如何实现这些新特征上。
请我喝杯咖啡,请使用支付宝扫描下方二维码:
原文地址:http://code.tutsplus.com/articles/overview-of-the-android-design-support-library–cms-24234
Android Design Support Library概览的更多相关文章
- Android Design Support Library使用详解
Android Design Support Library使用详解 Google在2015的IO大会上,给我们带来了更加详细的Material Design设计规范,同时,也给我们带来了全新的And ...
- Android开发学习之路-Android Design Support Library使用(CoordinatorLayout的使用)
效果图: 上面的这个图有两个效果是,一个是顶部的图片,在上滑之后会隐藏起来并且显示出一个ToolBar(ToolBar类似于ActionBar,但是只有ToolBar是兼容Material Desig ...
- 【转】【翻】Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
转自:http://mrfufufu.github.io/android/2015/07/01/Codelab_Android_Design_Support_Library.html [翻]Andro ...
- Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
原文:Codelab for Android Design Support Library used in I/O Rewind Bangkok session--Make your app fanc ...
- Codelab for Android Design Support Library used in I/O Rewind Bangkok session
At the moment I believe that there is no any Android Developer who doesn't know about Material Desig ...
- Android Design Support Library: 学习CoordinatorLayout
简述 CoordinatorLayout字面意思是"协调器布局",它是Design Support Library中提供的一个超级帧布局,帮助我们实现Material Design ...
- Material Design 开发利器:Android Design Support Library 介绍
转自:https://blog.leancloud.cn/3306/ Android 5.0 Lollipop 是迄今为止最重大的一次发布,很大程度上是因为 material design —— 这是 ...
- Android Design Support Library使用详解——Snackbar
Google在2015 I/O大会上,给我们带来了更加详细的Material Design规范,同时也引入了Android Design Support Library,为我们提供了基于Materia ...
- Android Design Support Library——Navigation View
前沿 Android 从5.0开始引入了Material design元素的设计,这种新的设计语言让整个安卓的用户体验焕然一新,google在Android Design Support Librar ...
随机推荐
- Apache不能启动: Unable to open logs
日志名称: Application来源: Apache Service日期: 2014/3/12 14:43:21事件 ID: ...
- java内存模型学习
根据 JVM 规范,JVM 内存共分为虚拟机栈.堆.方法区.程序计数器.本地方法栈五个部分. 虚拟机的内存模型分为两部分:一部分是线程共享的,包括 Java 堆和方法区:另一部分是线程私有的,包括虚拟 ...
- [python xml 学习篇][0]
tree = ET.parse("Result.xml")root = tree.getroot()print type(root)print root.tag # 得到root ...
- java EE技术体系——CLF平台API开发注意事项(4)——API生命周期治理简单说明
文档说明 截止日期:20170905,作者:何红霞,联系方式:QQ1028335395.邮箱:hehongxia626@163.com 综述 有幸加入到javaEE技术体系的研究与开发,也得益于大家的 ...
- CCF第四题无向图打印路径 欧拉问题
#include<iostream> #include<vector> #include<algorithm> #include<stack> #def ...
- 【转】Bad Smell(代码的坏味道)
1.Duplicated Code(重复的代码) 臭味行列中首当其冲的就是Duplicated Code.如果你在一个以上的地点看到相同的程序结构,那么当可肯定:设法将它们合而为一,程序会变得更好. ...
- centos中简易安装docker
centos中简易安装docker准备环境要求:请确保自己的centos的内核版本大于3.10,使用如下linux命令: uname -r1显示如下类似信息: 3.10.0-862.3.3.el7.x ...
- 刷题总结:排序机械臂(石室中学oj)(splay)
题目: 题目描述 为了把工厂中高低不等的物品按从低到高排好序,工程师发明了一种排序机械臂.它遵循一个简单的排序规则,第一次操作找到最低的物品位置 P1,并把从左起第 1 个至第 P1 个之间的物品反序 ...
- Eclipse + Jersey 发布RESTful WebService(一)了解Maven和Jersey,创建一个WS项目(成功!)
一.下文中需要的资源地址汇总 Maven Apache Maven网站 http://maven.apache.org/ Maven下载地址: http://maven.apache.org/down ...
- P1875 佳佳的魔法药水 (最短路,DP)
题目链接 Solution 好题. 一开始一直在想怎么蛇皮建图,但是发现一直蛇不出来... 正解是用类似于 dijkstra 的算法对所有点进行松弛. 对于每个元素记录两个值: \(cost\) 代表 ...