Android Material Design-Maintaining Compatibility (Compatibility)-(7)

Source: Internet
Author: User

Android Material Design-Maintaining Compatibility (Compatibility)-(7)

 

 

Some materialdesign functions such as material themes and custom activity transition can only be used in Android 5.0 (API level 21) or later system versions. However, you can design your app to use those features, whether on devices that support materialdesign or earlier Android versions.

 

Define optional styles

You can configure your app to use material design on devices that support it and use the old theme in earlier Android versions:

1. Define a topic that inherits an old topic (like Holo) and stores it in res/values/styles. xml.

2. Define a theme with the same name, inherit the material theme, and place it in res/values-21/styles. xml.

3. Set this topic in the manifest file as your app topic.

Note:If your app uses a material topic but does not provide an alternative topic, your app cannot run in the system before Android 5.0.

 

Provide alternative la s

If you do not use any new XML attributes introduced by Android5.0 according to the design guidelines to design your layout, they can run on earlier Android versions. Otherwise, you can provide an alternative layout. You can also provide alternative la s to customize what your app looks like in earlier Android versions.

When you create a layout for Android 5.0 (API level 21) or later, the layout file is placed in the res/layout-v21/folder, the alternative layout of earlier Android versions is placed in the res/layout/folder. 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/and place the styles modified for the new API in the res/values-v21/folder and use style inheritance, define the basic style in res/values/, in res/values-v21 /..

 

Supported libraries

V7 supports the following material design features:

L when you apply Theme. AppCompat themes, some controls have materialdesign style features.

L Theme. AppCompat has the Color palette theme attribute.

L RecyclerView controls display data sets.

L The CardView control creates a card.

L The Palette class extracts the highlighted color from the image.

 

System Controls

Theme. AppCompat themes provide material design styles for these controls:

L EditText

L Spinner

L CheckBox

L RadioButton

L SwitchCompat

L CheckedTextView

 

Color palette

To obtain the material design styles and custom color palette in the Android v7 support library, use a Theme. AppCompat topic:

 

 


 

 

List and card

The RecyclerView and CardView controls can be used in earlier Android versions using the Android v7 support package. However, these restrictions apply:

L CardView roll back to use a shadow with rules by using additional padding.

L CardView does not crop its subview and uses rounded corner intersection.

 

Dependency

To use these features in systems earlier than Android (API level 21), you need to add the Android v7 support library to your project. The following shows how to add 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.+'}

 

Supplement:In Eclipse, add dependencies. I have already explained in the previous blog (Android Material Design-Creating Lists and Cards (create list and card)-(3 )).


 

Check System Version

The following functions are only applicable to Android 5.0 (API level 21) and later versions:

L Activity transitions (Activity transition)

L Touch feedback (Touch feedback)

L Reveal animations (displays and exposes animations)

L Path-based animations (Path-based animation)

L Vector drawables (Vector drawing Resource)

L Drawable tinting (Drawable coloring)

To maintain compatibility with earlier Android versions, check the system version 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:Specify the versions supported by your app and declare them using the android: minSdkVersion and android: targetSdkVersion attributes in your manifest file. To use the material desing function in Android 5.0, set the value of the android: targetSdkVersionattribute attribute to 21 .. For more information, see API documentation.

 

 

-------------------------------------------------------Translation completion of the Material Design Series-------------------------------------------------------------

 

 


 

Related Article

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.