简体   繁体   中英

Material Design and devices restrictions

I've been wondering about Material Design uses on Android apps and devices' restrictions that it implies.

I have already developped for Android but themes usages seemed really confused at this moment (appcompat and stuff, i never really got it)

But apparently the last google i/o brought some tools to help the usage of Material Design in android apps.

So, my question is, how to properly use Material Design elements without restrict your app to a lot of devices ?

(I hope i'm being clear enough)

Use the Design Appcompat library to implement some Material features to work on pre-Lollypop devices, use real Material styles and components on Lollypop+.

This is done by providing alternative resources ( styles | themes.xml, layouts etc. ) using resource qualifier ( -v21 ).

In values-v21/themes.xml you put

<style name="MyAppBaseTheme" parent="android:Theme.Material">
    <item name="android:colorPrimary">@color/primary</item>
    ...

In values/themes.xml you put

<style name=”MyAppBaseTheme” parent=”Theme.AppCompat”>
    <item name=”colorPrimary”>@color/primary</item>
    ...
<style name=”MyAppTheme” parent=”MyAppBaseTheme”>  
    <!-- here you put the version-independent stuff -->

This way you're cleverly taking advantage of theme overriding, by just swapping the Material-related part and defining everything else a single time.

Note the proper android: prefix in non-Appcompat version. That is because in 5+ those attributes are part of the sdk, and in Appcompat they're custom, same class citizens as any of the styleables you define yourself.

Read the guide on maintaining compatibility , it will tell you about providing alternative style resources and splitting the codebase for post- and pre- 5.0

UPD Regarding your question in comments, will they be able to display material design too?

Here is a breakdown of support library version and flavours , the v* there indicates the minimum Android version needed to run said lib. Eg the generic v7 support library will give you the support of [a subset of] Material components and styles on devices all the way back to android 2.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM