Creating Apps with Material design--maintaining compatibility

Source: Internet
Author: User
Tags xml attribute

Reprint please specify Http://blog.csdn.net/eclipsexys translation from developer Android, time haste, there are translation questions please note that, thank you


Maintain compatibility

The transition portion of the material design function, such as material design and custom activities, is only available at Android5.0 (API level 21). However, you can design your application to run on a device that supports material design and still runs on devices that are compatible with earlier versions of Android that are running.

Define replaceable styles You can configure your application to use the material theme in support of it and revert to older theme devices that run earlier versions of Android devices:

Defines a theme that inherits old themes (such as holograms) in res/values/styles.xml下。
In res/values-v21/styles.xml中定义与继承Subject with the same name as the material theme.
Establish this topic as the subject of your application in the manifest file.

Note: If your application uses a material theme, but does not provide an alternative theme in this way, your application will not be able to run on Android version earlier than 5.0.


Provide alternative layouts If you follow the design guidelines without using any of the Android5.0 (API level 21) to launch the layout of the new XML attribute material design, they will not work in earlier versions of Android. However, you can provide a different layout. You can also provide another layout to customize your app to look like an earlier version of Android.

Create your layout file in Android5.0 (API level 21) res/layout-v21/and the layout file of your choice. res/layout/Earlier versions of Android. For example res/layout/my_activity.xmlIs es/layout-v21/my_activity.xmlA different layout.

To avoid repeating the code, define your styles, modify the style res/values-v21/使用New API and use style inheritance, limited to the basic style res/values/And those who inherit res/values-v21/


Using the Support library
The following material design features are included in the V7 support library R21 and above:

When you apply the material the design style acts on the Theme.appcompat theme of some system parts.
The theme properties of color palette in the Theme.appcompat theme.
The collection of data that is displayed in the Recyclerview widget.
Create a card in the CardView widget.
The color palette class extracts the highlighted color from the image.

System components

The Theme.appcompat theme provides material design styles in:


EditText
Spinner
CheckBox
RadioButton
Switchcompat
Checkedtextview


Color Palette

To get the material design style and custom palette with Android V7 Support Library, apply the 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 widgets can be applied to earlier versions of Android in these limits via the Android V7 Support library:

CardView falls back to a programmatic shadow implementation using additional padding.
CardView not clip and fillet intersection, its children views.

Dependent relationships
To use these features of Android older than the 5.0 (API level 21) version, including the Android V7 support for the project in the library as a gradle dependency:

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

Check System Version

The following features are only available for Android 5.0 (API level 21) above:


Activity transitions
Touch Feedback
Reveal Animations
path-based Animations
Vector Drawables
Drawable Tinting


To maintain compatibility with earlier versions of Android, invoke the API at run time to check the system version:

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}

Creating Apps with Material design--maintaining compatibility

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.