入门指南

如果要使用 Material Design 创建应用:

  1. 请查阅Material Design 规范
  2. 在您的应用中使用材料主题
  3. 遵循 Material Design 指导方针创建您的布局
  4. 指定您视图要投射阴影的高度
  5. 使用系统小组件呈现列表与卡片。
  6. 定制您的应用中的动画

保持后向兼容性

您可将多个 Material Design 功能添加至您的应用,同时保持与 Android 5.0 之前的 Android 版本的兼容性。 如果要了解更多信息,请参阅 保持兼容性

使用 Material Design 更新您的应用

如果要更新现有应用以纳入 Material Design,请遵循 Material Design 指导方针更新您的布局。 同时也须确保纳入深度、触摸反馈和动画。

使用 Material Design 创建新应用

如果您要使用 Material Design 功能创建新应用,Material Design 指导方针将为您提供一个紧密结合的设计框架。 请遵循这些指导方针并使用 Android 框架中的新功能来设计与开发您的应用。

使用材料主题


如果要在您的应用中使用材料主题,请指定一个从 android:Theme.Material 继承的风格:

<!-- res/values/styles.xml -->
<resources>
<!-- your theme inherits from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- theme customizations -->
</style>
</resources>

材料主题提供更新的系统小组件,让您能够为触摸反馈以及操作行为转换设置配色工具以及默认动画。 有关更多详情,请参阅使用材料主题

设计布局


除了应用及定制材料主题,您的布局同时也应符合Material Design 指导方针。 设计布局时,请特别注意下列几点:

  • 基线格点
  • 关键线
  • 间距
  • 触摸目标大小
  • 布局结构

指定您视图内的高度


视图可透射阴影,而视图的高度值将决定其阴影的大小以及其显示顺序。 如果要设置视图的高度,请使用您的布局中的android:elevation 属性:

<TextView
android:id="@+id/my_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next"
android:background="@color/white"
android:elevation="5dp" />

新的 translationZ 属性可让您创建反映出视图高度临时变化的动画。 高度变化可在响应触摸手势时发挥作用。

有关更多详情,请参阅定义阴影与裁剪视图

创建列表与卡片


RecyclerViewListView 的可插入版本,支持不同布局类型,具有更高性能。 CardView 让您能够展示卡片内的各种信息并且在各种应用中实现一致的呈现方式。 下列代码示例将展示如何将 CardView 包括在您的布局中:

<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="3dp">
...
</android.support.v7.widget.CardView>

如需了解详细信息,请参阅创建列表和卡片

定制您的动画


Android 5.0(API 级别 21)包括新 API,可用于在您的应用中创建定制动画。例如,您可启用操作行为转换并定义操作行为内的退出转换:

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// enable transitions
getWindow
().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
setContentView
(R.layout.activity_my);
}

public void onSomeButtonClicked(View view) {
getWindow
().setExitTransition(new Explode());
Intent intent = new Intent(this, MyOtherActivity.class);
startActivity
(intent,
ActivityOptions
.makeSceneTransitionAnimation(this).toBundle());
}
}

当您从此操作行为启动另一个操作行为时,退出转换将被激活。

如果要了解有关新动画 API 的更多详情,请参阅定义定制动画

分类面向开发者的 Material Design相关推荐:

面向开发者的 Material Design 入门指南 使用材料主题 创建列表与卡片 定义阴影与裁剪视图 使用图片 定义定制动画 维护兼容性