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. ORB-SLAM使用方法

    preparation:按照官網步驟完成ORB的安裝. 1.修改Camera calibration參數:到~/ORB_SLAM/Data/Settings.yaml修改 2.開啟終端機    -&g ...

  2. javaweb基础(37)_mysql数据库自动生成主键

    测试脚本如下: 1 create table test1 2 ( 3 id int primary key auto_increment, 4 name varchar(20) 5 ); 测试代码: ...

  3. data-ng-app 指令

    1.data-ng-app指令定义了一个AngularJS应用程序的根元素. 2.data-ng-app会在页面加载完毕后自动进行初始化应用程序. 3.data-ng-app可以通过一个值连接到代码模 ...

  4. javaScript校验图片大小、格式

    1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or ...

  5. Python学习之登陆认证

    需求: 让用户输入用户名密码 认证成功后显示欢迎信息 输错三次后退出程序 可以支持多个用户登录 (提示,通过列表存多个账户信息) 用户3次认证失败后,退出程序,再次启动程序尝试登录时,还是锁定状态(提 ...

  6. XStream 工具类 [ XmlUtil ]

    pom.xml <dependency> <groupId>com.thoughtworks.xstream</groupId> <artifactId> ...

  7. 超简单开发自己的php框架一点都不难

    (转)https://blog.csdn.net/qq_33862644/article/details/79344331 写框架的极简思路: 接收,打印参数想怎么弄.如 获取配置文件的方法,根据传过 ...

  8. proteus中蜂鸣器不响的原因

        本文参考自https://blog.csdn.net/gin_love/article/details/51168369 此网站.在用proteus仿真报警电路时,发现蜂鸣器不响.后在网上找了 ...

  9. 跨站请求伪造(csrf)中间件整理

    一. CSRF中间件 字面意思跨站请求伪造; 即模仿个请求朝服务器发送,django中对跨站伪造的请求有相应的校验 from django.views.decorators.csrf import c ...

  10. 《Cracking the Coding Interview》——第6章:智力题——题目6

    2014-03-20 01:14 题目:有100栈灯,一开始都关着.如果你按照n从1~100的顺序,每次都掰一下n的倍数的开关(开->关,关->开),那么到最后有多少灯是亮的? 解法:这个 ...