Getting Startedthis Lesson Teaches
- Apply the Material Theme
- Design Your Layouts
- Specify elevation in Your views
- Create Lists and Cards
- Customize Your Animations
You should also read
- Material Design Specification
- Material Design on Android
To create apps with material design:
- Review the material design specification.
- Apply the material theme to your app.
- Create your layouts following material design guidelines.
- Specify the elevation of your views to cast shadows.
- Use the system widgets for lists and cards.
- Customize the animations in your app.
Maintain backward compatibility
Can add many material design features to your apps while maintaining compatibility with versions of Android earlier tha N 5.0. For more information, see Maintaining compatibility.
Update your app with material design
To update a existing app to incorporate material design, update your layouts following material design guidelines. Also make sure to incorporate depth, touch feedback, and animations.
Create new apps with material design
If you is creating a new app with material design features, the material design guidelines provide your with a cohesive de Sign framework. Follow those guidelines and use the new functionality in the Android framework to design and develop your app.
Apply the Material Theme
To apply the material theme in your app, specify a style this inherits from 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>
The material theme provides updated system widgets that let's set their color palette and default animations for touch F Eedback and activity transitions. For more details, see Using the Material Theme.
Design Your Layouts
In addition to applying and customizing the material theme, your layouts should conform to the material design guidelines. When you design your layouts, pay special attention to the following:
- Baseline grids
- Keylines
- Spacing
- Touch Target Size
- Layout structure
Specify elevation in Your views
Views can cast shadows, and the elevation value of a view determines the size of its shadow and its drawing order. To set the elevation of a view with the android:elevation
attribute in your layouts:
<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" />
The new property translationZ
lets your create animations that reflect temporary changes in the elevation of a view. Elevation changes can is useful when responding to touch gestures.
For more details, see Defining Shadows and Clipping views.
Create Lists and Cards
RecyclerView
is a more pluggable version of this ListView
supports different layout types and provides performance improvements. CardView
Let s you show pieces of information inside cards with a consistent look across apps. The following code example demonstrates how to include a in CardView
your layout:
<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>
For more information, see Creating Lists and Cards.
Customize Your Animations
Android 5.0 (API level) includes the new APIs to the create custom animations in your app. For example, you can enable activity transitions and define a exit transition inside an activity:
PublicclassmyactivityextendsActivity{
@Override
protectedvoidonCreate(Bundlesavedinstancestate){
Super.onCreate(savedinstancestate);
//Enable Transitions
GetWindow().requestfeature(Window.feature_content_transitions);
Setcontentview(R.Layout.activity_my);
}
Publicvoidonsomebuttonclicked(ViewView){
GetWindow().setexittransition(NewExplode());
IntentIntent=NewIntent( This,myotheractivity.class);
StartActivity(Intent,
activityoptions
.makescenetransitionanimation( This).Tobundle());
}
}
When you start another activity from this activity, the exit transition is activated.
To learn more on the new animation APIs, see Defining Custom animations.
Material Design Series Second article--getting Started