Android 5.x 设计风格 Material Design
1.默认主题
@android:style/Theme.Material(dark version)
@android:style/Theme.Material.Light(light version)
@android:style/Theme.Material.Light.DarkActionBar(light version)
<style name="CMLAppTheme" parent="AppTheme">
<item name="android:colorPrimary">#BEBEBE</item>//主页的颜色
<item name="android:colorPrimaryDark">#FF5AEBFF</item>//状态栏的颜色
<item name="android:navigationBarColor">#FFFF4130</item>
</style>
2.elevation
xml中
<TextView
android:elevation="1dp"
android:text="djfkjfsdjfjdslkfjsdlkfjsdkljflsdjfl"
android:id="@+id/tv_rect"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:layout_width="100dp"
android:layout_height="100dp" />
代码中:
view.setTranslationZ(10);
3.Tinting
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:elevation="10dp"
android:src="@drawable/ic_launcher"
android:layout_gravity="center"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:elevation="5dp"
android:tint="@android:color/holo_blue_bright"
android:src="@drawable/ic_launcher"
android:layout_gravity="center"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:elevation="5dp"
android:tint="@android:color/holo_blue_bright"
android:tintMode="add"
android:src="@drawable/ic_launcher"
android:layout_gravity="center"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:elevation="5dp"
android:tint="@android:color/holo_blue_bright"
android:tintMode="multiply"
android:src="@drawable/ic_launcher"
android:layout_gravity="center"/>
如图所示
4.RecyclerView . CardView 详见Demo
Demo
5.Activity 过渡动画(进入,退出,共享元素)
进入退出动画效果(explode:分解,slide:滑动,fade:淡出)
共享元素
changeBounds :改变目标视图的布局边界
changeClipBounds :裁剪目标视图边界
changeTransform :改变目标视图的缩放比例和旋转角度
changeImageTransform :改变目标图片的大小和缩放比例
例如:设置ActivityA —>ActivityB
配置前期
ActivityA中:
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
ActivityB中:
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setEnterTransition(new Explode());
getWindow().setEnterTransition(new Slide());
getWindow().setEnterTransition(new Fade());
getWindow().setExitTransition(new Explode());
getWindow().setExitTransition(new Slide());
getWindow().setExitTransition(new Fade());
共享元素
Activity1–Activity2
两个Activity的布局文件中的共享元素必须增加属性
android:transitionName="xxx"
其中xxx为自定义,但是两个Activity布局中的xxx(名称)必须相同
然后:
Activity1中
startActivity(new Intent(this,ActivityB.class),ActivityOptions.makeSceneTransitionAnimation(this,view,"share").toBundle());//一个共享元素
startActivity(new Intent(this,ActivityB.class), ActivityOptions.makeSceneTransitionAnimation(this, Pair.create(imageView,getResources().getString(R.string.app_name)),
Pair.create(imageView2,"share")).toBundle());//多个共享元素
6.Ripple(点击时的波纹)动画效果
//波纹有边界
<Button
android:background="?android:attr/selectableItemBackgroundBorderless"
android:onClick="addRecycler"
android:layout_weight="1"
android:text="add"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
//波纹没有边界
<Button
android:background="?android:attr/selectableItemBackground"
android:onClick="delRecycler"
android:layout_weight="1"
android:text="del"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
7.Circular Reveal (循环显示)
例如:一个view以圆形的形式展开来等
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//圆形
Animator animator = ViewAnimationUtils.createCircularReveal(imageView, imageView.getWidth() / 2, imageView.getHeight() / 2, imageView.getWidth(), 0);
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(2000);
animator.start();
//左上角
Animator animator = ViewAnimationUtils.createCircularReveal(imageView2, 0, 0, 0, (float)Math.hypot(imageView2.getWidth(),imageView2.getHeight()));
animator.setInterpolator(new AccelerateDecelerateInterpolator());
animator.setDuration(2000);
animator.start();
}
});