问题描述
我在我的应用程序中使用v7支持AppCompatDialogFragment
I am using v7 support AppCompatDialogFragment in my app
import android.support.v7.app.AppCompatDialogFragment;
public class LoginDialogFragment extends AppCompatDialogFragment {
}
在整个应用中,我正在使用默认的Fragment
和FragmentManager
和否 android.support.v4.app.Fragment
或adroid.support.v4.app.FragmentManager
Throughout the app I am using default Fragment
and FragmentManager
and NOT android.support.v4.app.Fragment
or adroid.support.v4.app.FragmentManager
import android.app.Fragment;
import android.app.FragmentManager;
现在的问题是我想通过调用方法
Now the problem is I want to show the dialog from an Activity by calling the method
public void show(@NotNull android.support.v4.app.FragmentManager manager,
java.lang.String tag)
不接受 android.app.FragmentManager
作为参数.
所以我不能打电话
LoginDialogFragment loginDialogFragment = new LoginDialogFragment();
loginDialogFragment.show(getFragmentManager(), "tag");
现在如何显示对话?
推荐答案
您不能在 AppCompatDialogFragment .实际上,如果您仔细检查AppCompatDialogFragment
的导入,您会发现它来自支持库.您必须使用getSupportFragmentManager()
而不是getFragmentManager()
.喜欢
You can't use the native Fragment
support with AppCompatDialogFragment. In fact, if you check closer the import of AppCompatDialogFragment
, you will find out that it comes from the support library. You have to use getSupportFragmentManager()
instead of getFragmentManager()
. Like
loginDialogFragment.show(getSupportFragmentManager(), "tag");
AppCompat *中的所有内容都来自支持库
everything from AppCompat* is from the support library
这篇关于使用show()方法显示support.v7.AppCompatDialogFragment时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!