1.Activity转场动画

首先,把之前启动Activity的代码改成下面的写法:

(如果低版本需要加注解@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP))

 startActivity(new Intent(this, TestActivity.class), ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

在TestActivity中设置该Activity的进出场动画即可:

getWindow().setEnterTransition(new Explode().setDuration(2000));
getWindow().setExitTransition(new Explode().setDuration(2000));

在styles.xml文件中添加下面一行代码,表示激活Activity中元素的过渡效果:

<item name="android:windowContentTransitions">true</item>  

其他:滑动进入

    getWindow().setEnterTransition(new Slide().setDuration(2000));
getWindow().setExitTransition(new Slide().setDuration(2000));

其他:淡入淡出

getWindow().setEnterTransition(new Fade().setDuration(2000));
getWindow().setExitTransition(new Fade().setDuration(2000));

2.共享元素

1.view元素设置

view.setTransitionName( getString(R.string.transition_name)); 

2.相同元素设置都要添加xml

android:transitionName=”@string/transition_name”

3.代码中调用

Intent intent=new Intent(MainActivity.this, TestActivity.class);
ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation(MainActivity.this,
view, view.getTransitionName());
startActivityForResult(intent, 1, options.toBundle());

3.水波纹效果

在xml的background中设置即可

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#FF21272B">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
<corners android:radius="4dp" />
</shape>
</item>
<item android:drawable="@drawable/rounded_corners" />
</ripple>

4.Circular Reveal

当您显示或隐藏一组 UI 元素时,揭露动画可为用户提供视觉连续性。ViewAnimationUtils.createCircularReveal()
方法让您能够为裁剪区域添加动画以揭露或隐藏视图。

 // 先设置点击事件,然后直接在onClick中进行动画操作
@Override
public void onClick(View v) {
// 获取FloatingActionButton的中心点的坐标
int centerX = (v.getLeft() + v.getRight()) / 2;
int centerY = (v.getTop() + v.getBottom()) / 2;
// Math.hypot(x,y): 返回sqrt(x2 +y2)
// 获取扩散的半径
float finalRadius = (float) Math.hypot((double) centerX, (double) centerY);
// 定义揭露动画
Animator mCircularReveal = ViewAnimationUtils.createCircularReveal(
secondView, centerX, centerY, 0, finalRadius);
// 设置动画持续时间,并开始动画
mCircularReveal.setDuration(4000).start();
}

5.悬挂式notification

/**
* 悬挂式notification
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void openNotification() {
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(Notification.PRIORITY_DEFAULT)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle("悬挂 Notification")
.setContentText("一个悬挂notification.")
.setSubText(" Notification on Android 5.0"); Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(this, TestActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); //通过setFullScreenIntent将一个Notification变成悬挂式Notification
builder.setFullScreenIntent(pendingIntent, true); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0, builder.build());
}

 6.palette的使用

Palette 可以从一张图片中提取颜色,我们可以把提取的颜色融入到App UI中,可以使UI风格更加美观融洽。比如,我们可以从图片中提取颜色设置给ActionBar做背景颜色,这样ActionBar的颜色就会随着显示图片的变化而变化。

我们要想使用Palette,需要导入Palette的兼容库,Gradle 中添加下面依赖。

compile 'com.android.support:palette-v7:21.0.0'
 private void paletteTest(){
// 此方法可能会阻塞主线程,建议使用异步方法
//Palette palette = Palette.generate(bitmap); Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.bg);
// 异步提取Bitmap颜色
Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
// 提取完毕
// 有活力的颜色
Palette.Swatch vibrant = palette.getVibrantSwatch();
// 有活力的暗色
Palette.Swatch darkVibrant = palette.getDarkVibrantSwatch();
// 有活力的亮色
Palette.Swatch lightVibrant = palette.getLightVibrantSwatch();
// 柔和的颜色
Palette.Swatch muted = palette.getMutedSwatch();
// 柔和的暗色
Palette.Swatch darkMuted = palette.getDarkMutedSwatch();
// 柔和的亮色
Palette.Swatch lightMuted = palette.getLightMutedSwatch(); // 使用颜色
// 修改Actionbar背景颜色
getActionBar().setBackgroundDrawable(new ColorDrawable(vibrant.getRgb()));
// 修改文字的颜色
button6.setTextColor(muted.getTitleTextColor());
// 根据需求选择不同效果的颜色应用
}
});
}

7.阴影效果

android:elevation 设置该组件“浮”起来的高度,to难过过设置该属性可以让该组件呈现3D效果。

android:translationZ  设置该组件在Z方向(垂直屏幕方向)上的位移。

对应的Java方法:setElevation(float)  setTranslationZ(float)

<TextView
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="测试"
android:elevation="10dp"
android:translationZ="10dp"
android:textSize="18sp"/>

8.tint着色器

作用1:一张矢量图适配所有颜色
作用2:更优雅的selector实现方式

xml方式:

 <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image"
android:src="@mipmap/icon"
android:clickable="true"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image2"
android:src="@mipmap/icon"
android:tint="#FFCDD2"
android:clickable="true"
/>

Java代码

 Drawable drawable = ContextCompat.getDrawable(this,R.mipmap.icon);
Drawable.ConstantState state = drawable.getConstantState();
Drawable drawable1 = DrawableCompat.wrap(state == null ? drawable : state.newDrawable()).mutate();
drawable1.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
DrawableCompat.setTint(drawable,ContextCompat.getColor(this,R.color.pink));
imageView.setImageDrawable(drawable);
imageView1.setImageDrawable(drawable1);

9.clipping裁剪

            v1 = findViewById(R.id.tv_1);
v2 = findViewById(R.id.tv_2);
ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 10);
}
};
ViewOutlineProvider viewOutlineProvider1 = new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), view.getHeight() / 2);
}
};
v1.setOutlineProvider(viewOutlineProvider);
v2.setOutlineProvider(viewOutlineProvider1);

10.CardView卡片式控件

首先在build.gradle文件添加依赖库

基本属性:
app:cardBackgroundColor这是设置背景颜色
app:cardCornerRadius这是设置圆角大小
app:cardElevation这是设置z轴的阴影
app:cardMaxElevation这是设置z轴的最大高度值
app:cardUseCompatPadding是否使用CompatPadding
app:cardPreventCornerOverlap是否使用PreventCornerOverlap
app:contentPadding 设置内容的padding
app:contentPaddingLeft 设置内容的左padding
app:contentPaddingTop 设置内容的上padding
app:contentPaddingRight 设置内容的右padding
app:contentPaddingBottom 设置内容的底padding

 compile 'com.android.support:cardview-v7:24.2.0'

布局文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="@color/gray"> <android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardBackgroundColor="@color/blue"
app:cardCornerRadius="16dp"
app:cardElevation="16dp"> <TextView
android:id="@+id/id_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center"
android:textColor="@color/white"
android:textSize="20sp" />
</android.support.v7.widget.CardView>
</FrameLayout>

Android5.0新特性的更多相关文章

  1. Android5.0新特性之——按钮点击效果动画(涟漪效果)

    Android5.0 Material Design设计的动画效果 RippleDrawable涟漪效果 涟漪效果是Android5.0以后的新特性.为了兼容性,建议新建drawable-v21文件夹 ...

  2. Android5.0新特性-Material Design

    概述 2014年,Google携Android5.X重装归来.全新的UI设计和更加优化的性能,令开发人员眼前一亮 安装和配置Android5.0开发环境 开发Android还得靠AS.下载地址 htt ...

  3. Android5.0新特性——兼容性(support)

    兼容性 虽然Material Design新增了许多新特性,但是并不是所有新内容对对下保持了兼容. 使用v7包 v7 support libraries r21 及更高版本包含了以下Material ...

  4. Android5.0新特性:RecyclerView实现上拉加载更多

    RecyclerView是Android5.0以后推出的新控件,相比于ListView可定制性更大,大有取代ListView之势.下面这篇博客主要来实现RecyclerView的上拉加载更多功能. 基 ...

  5. Android5.0新特性——阴影和剪裁(shadow)

    阴影和剪裁 View的z属性 Material Design建议为了凸显布局的层次,建议使用阴影效果,并且Android L为了简化大家的工作,对View进行了扩展,能使大家非常方便的创建阴影效果: ...

  6. Android5.0新特性——图片和颜色(drawable)

    图片和颜色 tint属性 tint属性一个颜色值,可以对图片做颜色渲染,我们可以给view的背景设置tint色值,给ImageView的图片设置tint色值,也可以给任意Drawable或者NineP ...

  7. Android5.0新特性——全新的动画(animation)

    全新的动画 在Material Design设计中,为用户与app交互反馈他们的动作行为和提供了视觉上的连贯性.Material主题为控件和Activity的过渡提供了一些默认的动画,在android ...

  8. Android5.0新特性——新增的Widget(Widget)

    新增的Widget RecyclerView RecyclerView是ListView的升级版,它具备了更好的性能,且更容易使用.和ListView一样,RecyclerView是用来显示大量数据的 ...

  9. Android5.0新特性——Material Design简介

    Material Design Material Design简介 Material Design是谷歌新的设计语言,谷歌希望寄由此来统一各种平台上的用户体验,Material Design的特点是干 ...

  10. Android5.0新特性之——控件移动动画(初级)

    最近开发,UI大牛们设计了好多很炫酷吊炸天的动画,不由得重新学习了一下5.0的ObjectAnimator动画. ObjectAnimator动画的原理,通过反射控件的setXXX方法,改变控件的实际 ...

随机推荐

  1. Spring 学习之依赖注入

    什么是依赖关系? 纵观所有的Java 应用,从基于Applet的小应用到多层次结构的企业级别的应用,他们都是一种典型的依赖性应用,也就是由一些互相协作的对象构成的,Spring把这种互相协作的关系称之 ...

  2. 4、SpringBoot+Mybatis整合------一对多

    开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis/tree/c00b56dbd51a1e26ab9fd99020 ...

  3. 一个老鸟发的公司内部整理的 Android 学习路线图 Markdown 版本

    jixiaohua发了一篇一个老鸟也发了一份他给公司内部小伙伴整理的路线图.另一份 Android 开发学习路线图.可惜不是MarkDown格式的,所以jixiaohua直接上传的截图,在jixiao ...

  4. WebAppBuilder独立于Portal之arcgis for js应用框架研究

    1.前言 最近在做项目过程中,用到了WAB,先做一下总结和归类.Webappbuilder(简称WAB)是运行在portal或者online的一款webGIS开发应用程序,其代码开源并且具有优秀的设计 ...

  5. ES6初识-Decorator

    开始先按照个插件 npm install babel-plugin-transform-decorators-lagacy --save-dev 1.扩充和修改类的行为 2.修改的行为@readonl ...

  6. 深入浅出:了解JavaScript的ES6、ES7新特性

    参照阮一峰博客:http://es6.ruanyifeng.com/#README es6常见题:https://blog.csdn.net/qq_39207948/article/details/8 ...

  7. C++ Primer 学习笔记_Chapter4 数组和指针–指针

    一.什么是指针? 指针与迭代器一样,指针提供对其所指对象的间接访问,指针保存的是另一个对象的地址: string s("hello"); string *ps = &s; ...

  8. kangle环境liunx一键安装脚本

    1.kangle官方脚本 linux下easypanel版本安装及升级(集成了kangle web 服务器和mysql,仅支持centos 5和centos 6)执行下面的命令即可,安装程序将自动安装 ...

  9. POJ 2079 最大三角形面积(凸包)

    Triangle Description Given n distinct points on a plane, your task is to find the triangle that have ...

  10. WRITE命令 書式設定オプション

    書式設定オプション WRITE 命令では.さまざまな書式設定オプションが使用することができます. 構文 WRITE ....f option. 全データ型の書式設定オプション オプション 機能 LEF ...