Android Design Support Library And Material Design

2019-05-24 10:57发布

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!

2条回答
家丑人穷心不美
2楼-- · 2019-05-24 11:30

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'
查看更多
姐就是有狂的资本
3楼-- · 2019-05-24 11:32

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.

查看更多
登录 后发表回答