Material Design 入门

[TOC]
随着5.0版本的发布,带来了新版本的ui设计,那就是MaterialDesign。
如何保持兼容性:
在低于5.0的版本API21之前添加依赖:

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.+'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
}

但是有些为5.0独有
操作行为转换
触摸反馈
揭露动画
基于路径的动画
矢量图片
图片着色
为早期版本保持兼容

// Check if we're running on Android 5.0 or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Call some material design APIs here
} else {
    // Implement this feature without material design
}

material design有用的网站:http://www.materialdoc.com/

改变主题

将继承的主题改为Theme.AppCompat
颜色说明

继承AppCompatActivity

是FragmentActivity的子类。活动应该改为继承AppCompatActivity

使用ActionBar

getSupportActionBar.show();

使用MD图标

MaterialNavagation Drawer

Material Views

  1. RecyclerView
  2. CardView
  3. ToolBar
  4. Floating action bars
  5. material animations
  6. ripple animations
    触摸发聩提供了视觉瞬间的确认反馈,当用户与ui元素交互时,通常用于可触摸的元素。为了指定资源
    对于可点击的View
    android:background:"?android:attr/selectableItemBackground"
    对于按钮

  7. shared Element Transitions

  8. Circular Reveal
  9. Scrolling Anmations
    #Material 风格
    ##elevation和shadows高度和阴影

引入了高度的概念,在代码中可以用getElevation() or setElevation()

<ImageViewandroid:elevation="8dp" />

Dynamic Color Palettes动态调色板

从图片提取出的颜色创造出沉浸的感觉,增加静谧的氛围和最佳的可读性。
低版本支持:

compile 'com.android.support:palette-v7:21.0.+'

生成调色板

Palette.Builder用来创建调色板,提供方法设置最大数量的颜色和同步生成和异步生成。

  1. 同步
    当你正在访问图片下载线程
Palette.from(bitmap).generate();
Palette.from(bitmap).maximumColorCount(numberOfColors).generate();
  1. 异步
    generate 方法传递一个PaletteAsyncListener,就会执行一个异步的任务,手机图片的信息
// This is the quick and easy integration path. 
// May not be optimal (since you're dipping in and out of threads)
Palette.from(bitmap).maximumColorCount(numberOfColors).generate(new Palette.PaletteAsyncListener() {
    @Override
    public void onGenerated(Palette palette) {
         // Get the "vibrant" color swatch based on the bitmap
         Palette.Swatch vibrant = palette.getVibrantSwatch();
          if (vibrant != null) {
              // Set the background color of a layout based on the vibrant color
              containerView.setBackgroundColor(vibrant.getRgb());
              // Update the title TextView with the proper text color
              titleView.setTextColor(vibrant.getTitleTextColor());
          }
    }
});

调整颜色的数量

对于风景来说,12-16.对于很多人脸组成的图片24-32

属性

当调色板生成时,会自动生成6个样本
- Vibrant. –>Palette.getVibrantSwatch()
- Vibrant dark.–> Palette.getDarkVibrantSwatch()
- Vibrant light. –>Palette.getLightVibrantSwatch()
- Muted. –>Palette.getMutedSwatch()
- Muted dark.–> Palette.getDarkMutedSwatch()
- Muted light. –>Palette.getLightMutedSwatch()
每个样本的属性:
- getPopulation(): the amount of pixels which this swatch represents.
- getRgb(): the RGB value of this color.
- getHsl(): the HSL value of this color.
- getBodyTextColor(): the RGB value of a text color which can be displayed on top of this color.
- getTitleTextColor(): the RGB value of a text color which can be displayed on top of this color.
titleTextColor:对于对比度要求较小更加的透明
bodyTextColor:由于字体较小所以要求高对比度。

Dialog Styles

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值