Android Design Support Library And Material Design Backwards Compatibility?

。_饼干妹妹 提交于 2019-12-10 10:59:45

问题


I'm new here, so bear with me! I'm sorta confused about the new Design Support Library (and how one implements support libraries), and I had a two questions:

  • I'm confused about how support libraries are implemented. Is it something as simple as saying 'if the OS version is below version 5.0, use the V7 support library', or would I have to code an 'Alternative Layout'(One for devices running +5.0, and one for devices running older version of android?)
  • Does the Design Support Library replace or add-to the V7 support libraries? (If I wanted to include, say, cards and a snack bar in an app, would I be able to just use the Design Support Library or would I have to use it along with the v7 cardview library? I know it's a stupid question, but I just want to make sure.)

Thanks a lot!


回答1:


You can use the support libraries to backport some features introduced with the last api (for example 21) to old devices running a previous api level.

For example, API21 introduced a new widget, the Toolbar. This widget can be used only in device with API >=21.

With the appcompat rel.21 (a v7 Support library) you can use the Toolbar (pay attention to the package) to implement your Toolbar in old devices running API>=7.

This can happen because the support libraries are included in your apk.

The Design Support Library is a new library which add new features. It contains views as Snackbar, TextInputLayout, FloatingActionButton, but it doesn't contain the Card.

So use this dependency for the design support library:

compile 'com.android.support:design:22.2.0'

This dependency to use the AppCompat library

compile 'com.android.support:appcompat-v7:22.2.0'

This dependency for the official CardView

compile 'com.android.support:cardview-v7:22.2.0'

Check the official doc for more info.




回答2:


I'm confused about how support libraries are implemented. Is it something as simple as saying 'if the OS version is below version 5.0, use the V7 support library', or would I have to code an 'Alternative Layout'(One for devices running +5.0, and one for devices running older version of android?)

The libraries takes care for you of compatibility for pre-Lollipop (and pre-M) devices for the views contained in it.

Does the Design Support Library replace or add-to the V7 support libraries? (If I wanted to include, say, cards and a snack bar in an app, would I be able to just use the Design Support Library or would I have to use it along with the v7 cardview library? I know it's a stupid question, but I just want to make sure.)

Add-to. The design support library contains some views exclusive for helping to achieve a perfect "materialized" app. For RecyclerView, CardView, Palette etc, you must use their separate support libraries. E.g.:

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:design:22.2.0'


来源:https://stackoverflow.com/questions/30550338/android-design-support-library-and-material-design-backwards-compatibility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!