简体   繁体   English

编写Android库:使用AppCompat吗?

[英]Writing an Android library: use AppCompat?

When writing an Android library, should I use the AppCompat or Support variants provided by the support library? 编写Android库时,应该使用支持库提供的AppCompatSupport变体吗?

For example, should a method take an Activity or an AppCompatActivity ? 例如,方法应采用Activity还是AppCompatActivity support.v4.Fragment or android.app.Fragment ? support.v4.Fragment还是android.app.Fragment

In general you should use the AppCompat libraries wherever possible. 通常,应尽可能使用AppCompat库。 The library provides backporting for some new features (whatever is practical), and fixes bugs in various version specific versions. 该库提供了一些新功能(无论实际如何)的反向移植,并修复了各种特定于版本的错误。 For Activities and Fragments its particularly important, as Fragments at least had major differences between versions. 对于活动和片段,它尤其重要,因为片段之间至少在版本之间存在重大差异。

AppCompatActivity is the base class that support Support library ActionBar while Activity is actually the parent of AppCompatActivity. AppCompatActivity是支持支持库ActionBar的基类,而Activity实际上是AppCompatActivity的父级。 Depending on your purpose of library, if you have no intention of using the Support library ActionBar / Fragment related feature in your library, I would say, in general, the activity class is sufficient for your library. 根据您的库目的,如果您不打算在库中使用与支持库ActionBar / Fragment相关的功能,那么我通常会说,活动类对于您的库就足够了。

在此处输入图片说明

android.app.Fragment has been deprecated now with API 28. So just go for the support Fragment version . 现已使用API​​ 28弃用了android.app.Fragment。因此,只需获取支持Fragment版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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