2017-07-20 36 views
3

我想我可能误解了在线文档,但在使用Android设计支持库实现Android应用材质设计方面有很多。Android:我可以使用Design Support Library而不是AppCompat来设计Material Design UI吗?

我有一个最低SDK为14的应用程序,我可以增加到16.我不使用协调器布局或任何东西,但对Material Design Theme和Snackbar具有以下依赖关系。

compile 'com.android.support:appcompat-v7:25.3.1' 
compile 'com.android.support:design:25.3.1' 

我不知道我是否可以删除依赖于程序兼容性,而是只使用设计支持库,以实现材料的设计主题,但我无法找到如何得到这个。或者我错误地理解了这一点?

+0

你会得到什么错误? –

回答

0

您可以省略appcompat依赖项,因为design对它有依赖性。验证您可以使用Gradle依赖关系树。在这里它看起来如何。我使用com.android.support:design:24.2.1

+--- com.android.support:design:24.2.1 
| +--- com.android.support:support-v4:24.2.1 
| | +--- com.android.support:support-compat:24.2.1 
| | | \--- com.android.support:support-annotations:24.2.1 
| | +--- com.android.support:support-media-compat:24.2.1 
| | | \--- com.android.support:support-compat:24.2.1 (*) 
| | +--- com.android.support:support-core-utils:24.2.1 
| | | \--- com.android.support:support-compat:24.2.1 (*) 
| | +--- com.android.support:support-core-ui:24.2.1 
| | | \--- com.android.support:support-compat:24.2.1 (*) 
| | \--- com.android.support:support-fragment:24.2.1 
| |   +--- com.android.support:support-compat:24.2.1 (*) 
| |   +--- com.android.support:support-media-compat:24.2.1 (*) 
| |   +--- com.android.support:support-core-ui:24.2.1 (*) 
| |   \--- com.android.support:support-core-utils:24.2.1 (*) 
| +--- com.android.support:appcompat-v7:24.2.1 
| | +--- com.android.support:support-v4:24.2.1 (*) 
| | +--- com.android.support:support-vector-drawable:24.2.1 
| | | \--- com.android.support:support-compat:24.2.1 (*) 
| | \--- com.android.support:animated-vector-drawable:24.2.1 
| |   \--- com.android.support:support-vector-drawable:24.2.1 (*) 
| \--- com.android.support:recyclerview-v7:24.2.1 
|   +--- com.android.support:support-annotations:24.2.1 
|   +--- com.android.support:support-compat:24.2.1 (*) 
|   \--- com.android.support:support-core-ui:24.2.1 (*) 

为了自己使用它

摇篮(右上标签) - >执行摇篮任务(gradle这个符号) - >确保您在:app - >运行app:dependencies

因此com.android.support:design:25.3.1将具有com.android.support:appcompat-v7:25.3.1作为依赖关系。

+0

我想你的回答间接地回答了我的问题,因为我需要Snackbar,并且依赖于AppCompat的pre-sdk-22,所以这是不可能的。它并没有让我感到困扰,但为Material Design Theme设计了一个完整的支持库似乎有点矫枉过正。任何选择?我大概可以没有小吃店。 –

+0

@ShahidThaika支持库通常是一个好主意,因为它们通常是向后兼容的。在下一次sdk更新中,您自己的解决方案可能已过时。 –

0

比较好的方法是使用AppCompat,就像在老版本的Android中一样,它会调整一切。这也取决于你要使用哪个视图:如果它是普通的按钮或编辑文本,最好使用标准的。因为所有的Android版本都支持它们。