如果我支持SDK15,我应该使用support-v4 Fragment而不是Fragment吗
我正在尝试使用FragmentSupport.shouldShowRequestPermissionRationale(this)并实现新的M权限模型,但它需要一个片段。
例如:
import android.support.v4.app.Fragment;
public class MyBaseFragment extends Fragment {
public ... {
if (FragmentCompat.shouldShowRequestPermissionRationale(this)){ // ERROR, needs Fragment not v4 Fragment
....
}
}
}FragmentCompat:http://developer.android.com/reference/android/support/v13/app/FragmentCompat.html
发布于 2015-09-23 01:11:15
如果你使用的是像标签这样的布局(比如ViewPager),那么就需要支持库。在使用"only“片段和minSDK 15的情况下,它们不是necessary.By的方式,使用支持库是很好的,因为它不需要太多的努力,并且您可以在以后需要时进行更改。您可以在这里阅读详细的documentation,以了解您的项目是否需要它。
发布于 2018-03-28 20:25:18
应该在任何地方使用android.support.v4.app.Fragment而不是android.app.Fragment,因为后者在Android9中已被弃用。
发布于 2016-09-20 00:36:23
android.app.Fragment是在API级别11中引入的。如果您的minSDKVersion < 11,则必须使用android.support.v4.app.Fragment类来支持向后兼容。正如你所提到的,你的应用程序的API15级,你必须使用android.app.Fragment。
https://stackoverflow.com/questions/32722740
复制相似问题