Reprint Please specify source: http://blog.csdn.net/bbld_/article/details/40634829
Translated from: http://developer.android.com/training/material/compatibility.html
Some of the features in materialdesign like material themes and their own transitions to define activity can only be used in the Android 5.0 (API level 21) or the system version number above. But you can design your app to use those features, whether on a device that supports Materialdesign or an earlier Android version number.
Define an optional style
You can configure your app to use material design on the device that supports it, using the old theme in the earlier Android version number:
1. Define a theme. It inherits an old theme (like holo). Put it in the res/values/styles.xml.
2. Define a theme of the same name, inheriting the material theme, and placing it in res/values-21/styles.xml.
3. Set this theme in the manifest file for your app theme.
Note: If your app uses the material theme but does not provide an alternative theme, your app will not be able to perform in a system prior to Android 5.0.
Provides an alternative layout
Suppose you design your layout based on the design guidelines without using the new XML attributes introduced by whatever Android5.0. They can be executed on Android's earlier version number. Otherwise, you can provide an alternative layout. You can also provide an alternative layout. Define your app as it appears on the previous Android version number.
Layout files are placed in the res/layout-v21/ directory when creating layouts for Android 5.0 (API level 21) or above. An alternative layout for earlier Android version numbers is placed in the res/layout/ directory. For example,Res/layout/my_activity.xml is an alternative layout for Res/layout-v21/my_activity.xml
To avoid repeated code, define your style resources in res/values/ . The styles that were changed for the new API are placed in the res/values-v21/ directory. and use style inheritance to define the primary style in res/values/ . In res/values-v21/. The primary style is inherited from.
Using the Support library
The v7 Support library R21 and above version numbers include the following material design features:
L When you apply the theme.appcompat theme. Some controls have the characteristics of materialdesign style .
L Theme.appcompat has a Color palette Theme property.
The L recyclerview control displays the data collection.
L CardView control to create a card.
L Palette to extract the prominent color from the image.
System controls
The theme.appcompat theme provides material design styles for these controls:
L EditText
L Spinner
L CheckBox
L RadioButton
L Switchcompat
L Checkedtextview
Color palette
In order to get material design styles in the Android V7 Support library and define your own palette, use a theme.appcompat theme:
<!--extend one of the Theme.appcompat themes--><style name= "Theme.mytheme" parent= "Theme.AppCompat.Light" > <!--Customize the color palette- <item name= "colorprimary" > @color/material_blue_500< /item> <item name= "Colorprimarydark" > @color/material_blue_700</item> <item name= " Coloraccent "> @color/material_green_a200</item></style>
Lists and cards
The recyclerview and CardView controls can be used on earlier Android version numbers via the Android V7 support package. But there are these restrictions:
L CardView fallback to use a shaded shadow by using an extra fill.
L CardView does not crop its child views. Intersect with rounded corners.
Depend on
These features are to be used in systems older than Android5.0 (API level 21). To join the Android V7 Support library to your project, the following is the join gradle dependency :
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.+ '}
Add: Eclipse joins dependencies in the previous blog I have made instructions (Android Material design-creating Lists and Cards (create lists and cards)-(iii)).
Check the system version number
The following features are only available for Android 5.0 (API level 21) above:
L Activity Transitions (transition of activity)
L Touch Feedback (touch feedback)
L Reveal animations (show, expose animation)
L path-based Animations (path-based animation)
L vector drawables (vector drawing resources)
L drawable Tinting (drawable coloring)
In order to maintain compatibility with earlier Android version numbers. Check the version number of the system before calling these APIs:
Check if we ' re running on Android 5.0 or Higherif (Build.VERSION.SDK_INT >= build.version_codes. LOLLIPOP) { //Call some material design APIs here} else { //Implement This feature without material design}
Note: to specify the version number that your app can support, use android:minsdkversion and android:targetsdkversion in your manifest file attribute to declare. To use the material desing feature in Android 5.0, set the value of the Android:targetsdkversionattribute property to 21: For a lot of other information please refer to <uses-sdk> API documentation.
----------------------------------------------------------------- The end of the translation of the Material Design Series ----------------------------------------------------------------------
Android Material design-maintaining compatibility (keep compatibility)-(vii)