supportFragmentManager.commit 在科特林中不起作用
supportFragmentManager.commit in kotlin is not working
谁能帮我解决这个问题?在我的片段中 supportFragmentManager.commit{} 不工作。 Android Studio 无法识别我不知道该怎么做。我在 kotlin 项目工作
commit {}
方法(在 lambda 中使用事务)是 Fragment KTX 库提供的扩展函数。如果你还没有,你需要在 build.gradle
:
中添加这个依赖
dependencies {
implementation "androidx.fragment:fragment-ktx:1.2.5"
}
然后 Android Studio 应该会自动提供通过导入来修复 commit
调用。如果没有(有时会很尴尬),请将其添加到您的导入中:
import androidx.fragment.app.commit
也许还有这些,我不知道是否有必要
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
您可能需要删除一些其他匹配的导入,以便您只使用 androidx
版本
谁能帮我解决这个问题?在我的片段中 supportFragmentManager.commit{} 不工作。 Android Studio 无法识别我不知道该怎么做。我在 kotlin 项目工作
commit {}
方法(在 lambda 中使用事务)是 Fragment KTX 库提供的扩展函数。如果你还没有,你需要在 build.gradle
:
dependencies {
implementation "androidx.fragment:fragment-ktx:1.2.5"
}
然后 Android Studio 应该会自动提供通过导入来修复 commit
调用。如果没有(有时会很尴尬),请将其添加到您的导入中:
import androidx.fragment.app.commit
也许还有这些,我不知道是否有必要
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
您可能需要删除一些其他匹配的导入,以便您只使用 androidx
版本