Android5.0新控件
谷歌在推出Android5.0的同时推出了一些新控件,Android5.0中最常用的新控件有下面5种。
1. CardView(卡片视图)
CardView顾名思义是卡片视图,它继承FrameLayout。它是一个带圆角的背景和阴影FrameLayout。CardView被包装为一种布局,并且经常在ListView和RecyclerView的Item布局中,作为容器使用。
CardView的使用非常简单:
1 <android.support.v7.widget.CardView 2 android:layout_width="match_parent" 3 android:layout_height="60dp"> 4 <Button 5 android:id="@+id/ripple_button" 6 android:layout_width="match_parent" 7 android:layout_height="50dp" 8 android:layout_gravity="center" 9 android:layout_margin="5dp" 10 android:background="@drawable/ripple" 11 android:gravity="center" 12 android:text="我在一个CardView里面" /> 13 </android.support.v7.widget.CardView>
2. Patelle(调色板)
Patelle是一个辅助类,它的作用是从图片中获取突出的颜色。
它可以提取下面几种特性的突出颜色:
- Vibrant(充满活力的)
- Vibrant Dark(充满活力,黑暗的)
- Vibrant Light(充满活力的,明亮的)
- Muted(柔和的)
- Muted Dark(柔和的,黑暗的)
- Muted Light(柔和的,明亮的)
Patelle的使用也非常简单:
1 // 获取应用程序图标的Bitmap 2 bitmap= BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); 3 // 通过bitmap生成调色板palette 4 Palette palette=Palette.from(bitmap).generate(); 5 // 获取palette充满活力色颜色 6 int vibrantColor=palette.getVibrantColor(Color.WHITE);
3. Toolbar(工具栏)
Toolbar顾名思义是工具栏,作为ActionBar的替代品出现,谷歌推荐使用Toolbar替代ActionBar。
Toolbar可以放置在任何地方,不像ActionBar一样只能放置在固定的位置。
Toolbar支持比ActionBar更集中的特征。
Toolbar可能包含以下可选元素的组合:
- 导航按钮
- 品牌的Logo图像
- 标题和子标题
- 一个或多个自定义视图
1 this.toolbar = (Toolbar) findViewById(R.id.toolbar); 2 this.recyclerview = (RecyclerView) findViewById(R.id.recycler_view); 3 this.ripplebutton = (Button) findViewById(R.id.ripple_button); 4 this.button = (Button) findViewById(R.id.button); 5 // 设置Logo 6 toolbar.setLogo(R.mipmap.ic_launcher); 7 // 设置标题 8 toolbar.setTitle("Android5.0"); 9 // 设置子标题 10 toolbar.setSubtitle("新控件"); 11 //设置ActionBar,之后就可以获取ActionBar并进行操作,操作的结果就会反应在toolbar上面 12 setActionBar(toolbar); 13 //设置了返回箭头,,相当于设置了toolbar的导航按钮 14 getActionBar().setDisplayHomeAsUpEnabled(true);
4. RippleDrawable(波纹图)
RippleDrawable顾名思义是波纹图,只能在Android5.0以上使用,目前还没有提供RippleDrawable向下兼容的支持包。
RippleDrawable可显示一个涟漪效应响应状态变化 。
定义一个UI的背景图片为RippleDrawable
android:background="@drawable/ripple"
在drawable文件夹下面定义一个RippleDrawable的xml文件
<?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android"android:color="#0000FF"><item><shape android:shape="rectangle"><solid android:color="#FFFFFF" /><corners android:radius="4dp" /></shape></item> </ripple>
android:color
:表示波纹的颜色
<item>
:表示波纹图下面的条目
来看一下点击按钮的波纹效果
5. RecyclerView(循环视图)
RecyclerView是ListView的替代品,谷歌推荐使用RecyclerView替代ListView。
RecyclerView提供比ListView更加灵活的使用,并且性能比ListView更优。
RecyclerView可以设置线性,网格,瀑布流式三种布局管理器。
- LinearLayoutManager(线性布局管理器)
- GridLayoutManager(网格布局管理器)
- StaggeredGridLayoutManager(瀑布流式布局管理器)
注意:RecyclerView,Patelle,CardView是在单独的支持包里面,不在appcompat-v7及其依赖子包中
要使用它们,必须导入它们的依赖包
compile 'com.android.support:recyclerview-v7:23.1.1'compile 'com.android.support:palette-v7:23.1.1'compile 'com.android.support:cardview-v7:23.1.1'
转载于:https://www.cnblogs.com/ganchuanpu/p/8394852.html
Android5.0新控件相关推荐
- Android 5.0新控件——FloatingActionButton(悬浮按钮)
Android 5.0新控件--FloatingActionButton(悬浮按钮) FloatingActionButton是5.0以后的新控件,一个悬浮按钮,之所以叫做悬浮按钮,主要是因为自带阴影 ...
- 【Android】Anroid5.0+新控件---酷炫标题栏的简单学习
Android5.0+推出的新控件感觉特别酷,最近想模仿大神做个看图App出来,所以先把这些新控件用熟悉了. 新控件的介绍.使用等等网上相应的文章已经特别多了,题主也没那能力去写篇详解出来,本篇随笔记 ...
- Android M 新控件了解学习
Android M 新控件了解:FloatingActionButton,TextInputLayout,Snackbar,TabLayout, AppBarLayout,NavigationView ...
- 【转】Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用...
Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用 分类: Android UI ...
- 一个Activity掌握Design新控件 (转)
原文地址:http://blog.csdn.net/lavor_zl/article/details/51295364 谷歌在推出Android5.0的同时推出了全新的设计Material Desig ...
- 【开源】QuickPager ASP.NET2.0分页控件V2.0.0.3 【增加了使用说明】
================================ 欢迎转载,但是请注明出处.本文出自博客园 .谢谢合作! ================================ 最新版本:V ...
- NavigationDrawer和NavigationView-Android M新控件
Translucent System Bars-4.4新特性 Toolbar-5.0新特性 NavigationDrawer 简介 NavigationDrawer 是 Google 在 Materi ...
- Delphi XE2 新控件 布局Panel TGridPanel TFlowPanel
Delphi XE2 新控件 Firemonkey 布局Panel Windows平台VCl TGridPanel TFlowPanel FMX 跨平台 TLayout TGridLayout TFl ...
- ASP.Net2.0 数据绑定控件的优越性在哪里?
尽管有丰富.功能强大的编程接口,ASP.NET 1.x DataGrid 控件仍需要编写大量自定义代码来处理普通操作,如分页.排序.编辑和删除数据.例如,当用户单击以保存或取消更改时,DataGrid ...
最新文章
- 写代码神器!双屏敲代码飞起,包邮送一台!
- python调用bat有时可以、有时不行_python编程实现对远程执行bat文件时遇到的错误...
- Python教程:threading中join与setDaemon的用法及区别讲解
- jquery绑定元素id事件_JQuery绑定click事件的3种写法
- day02(下)_运算符
- Spring Data对Cassandra 3的支持
- 期权数据 获取_我如何免费获得期权数据
- windows下手动配置ipv6地址
- c语言case key pres,C#程序设计B-中国大学mooc-题库零氪
- eclipse中选中一个单词 其他相同的也被选中 怎么设置
- grub2与grub区别
- 《Entity Framework 6 Recipes》中文翻译——第十二章自定义EntityFramework对象(一)...
- Netty实现高性能IOT服务器(Groza)之手撕MQTT协议篇上
- 博图V13、V14、V15、V15.1、V16版本安装包链接下载
- 2021年中国上市公司发明授权数量及分布:发明授权数量连续5年增长,广东省位居全国第一[图]
- Android webview 下载文件(文件名,扩展名)
- 国外的英文JAVA论坛
- vmware虚拟机centos7扩容
- 研究知识追踪/学生模型的一些学校和人物
- 关于sammy的初理解
热门文章
- BugkuCTF-WEB题速度要快
- php时间转分钟前,PHP把时间转换成几分钟前几小时前几天前
- python字符串乘一个数_Python--初识庐山真面目
- jAvA中deprecate,在Java中使用Deprecated方法或类是错误的吗?
- java ajax报错500,(Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决
- php 图片印章_php工具型代码之印章抠图
- android 左右卡片切换,3D卡片切换
- circlegan_【源码解读】cycleGAN(二) :训练
- matlab里dcgain,制系统的时域分析
- 西南科技大学城市学院计算机专科,西南科技大学城市学院官网