android - 如何在 Activity 中使用 getSupportFragmentManager()

标签 android android-fragments

当我改变的时候

public class Bmr extends Activity implements View.OnClickListener {

public class Bmr extends appcompatactivity implements View.OnClickListener {

getSupportFragmentManager() 正在运行,但我需要使用 Activity 类。有什么方法可以选择吗?

最佳答案

不能getSupportFragmentManager() 仅在 FragmentActivity 中可用以及扩展它的类。

来自docs ,你可以看到 AppCompatActivity 是一个 Activity,所以 Activity 中的所有内容在 AppCompatActivity 中也可用。

java.lang.Object
   ↳    android.content.Context
       ↳    android.content.ContextWrapper
           ↳    android.view.ContextThemeWrapper
               ↳    android.app.Activity
                   ↳    android.support.v4.app.FragmentActivity
                       ↳    android.support.v7.app.AppCompatActivity

关于android - 如何在 Activity 中使用 getSupportFragmentManager(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38895333/

相关文章:

Android Studio Flutter 无法编译到 iOS

java - MultiAutocompleteTextView 事件

java - 相对布局中的 ViewPager 消耗完整高度(选项卡)

android - 抽屉导航项目是具有选项卡的 fragment

javascript - Angular 4 typescript Cordova相机插件错误 "Property '相机'在类型 'Navigator'上不存在”

java - 实现 AutoCompleteTextView 的应用程序在启动时崩溃

android - 如何以编程方式在android中获取连接的wifi路由器的IP地址?

android - 检测底部工作表对话框 fragment 在基础 fragment 上消失

android - 从 fragment 内部获取父 ViewPager View

android - 找不到 fragment.jar (androidx.fragment :fragment:1. 0.0)