Support Library详解之Design Support
什么是Design Support Library
Design Support Library提供了用于向您的App添加Material Design(材料设计)风格的组件样式API。
那么Design Support Library都有什么呢?它包括:navigation drawers,floating action buttons (FAB), snackbars, 和 tabs 以及Material Design的EditText等等.
我们该如何添加Design Support Library支持呢?
很简单 如果你在使用Android Studio的话那么你只需要添加一句话

好吧,如果你是小白又对Material Design十分的感兴趣那我不介意多写一点,如果你是大神那么可以跳过这一部分。



那么我们应该如何使用Design Support Library呢?
1.SnackBar
Snackbar提供了一个介于Toast和AlertDialog之间轻量级控件,它可以很方便的提供消息的提示和动作反馈。他的使用用法与Toast基本一致但是他可以对点击事件有更好的支持。


Google API 官方说明文档地址:
http://developer.android.com/reference/android/support/design/widget/Snackbar.html
2.Floating Action Button
fab是一个圆形的按钮,谷歌建议这个按钮用作积极的意义,比如添加收藏等等,最好不要用于如删除等操作。他的默认颜色为主题中colorAccent。

FloatingActionButton-fab的使用非常简单,把他当做一个button就可以了,最好是配合CoordinatorLayout布局使用,这个布局类似于一个加强的Framelayout,这个我们之后会提到的。

fab有两种大小如果你希望使用一个小一点的可以在xml中添加一句这样的话:app:fabSize="mini"
另外他还可以设置FloatingActionButton.OnVisibilityChangedListener,用于监控他显示还是隐藏的改变
Google API 官方说明文档地址:
http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html
3.TextInputLayout
TextInputLayout作为一个父容器控件,包装了新的EditText。一般情况下,单独的EditText会在用户输入第一个字母之后就隐藏hint提示信息,但是现在你可以使用TextInputLayout 结合EditText使提示信息变成一个显示在EditText之上的标签,他的默认颜色也是主题中colorAccent。



TextInputEditText



4.TabLayout
tablayout是用来实现标签的,那么他应该如何与ViewPager配合使用呢?
很简单:1,通过setOnTabSelectedListener设置一个监听器来响应选项卡的选择状态 2,通过setTabsFromPagerAdapter来使用PagerAdapter的page title 3,使用TabLayout.TabLayoutOnPageChangeListener来联动滑动



大致上说Design库有几种控件,下一次我们将一起感受一直他的layout部分。