我想用 LinearLayout
创建一个空的 DialogFragment
,然后更改 LinearLayout
中的 fragment 。例如,第一个 fragment 是 3 按钮(facebook、google+、电子邮件登录)的登录,当有人按下电子邮件时,第 2 个 fragment 的布局为 EditTexts
如果按下 Google 或 Facebook,则其他 fragment 出现时带有 ProgressBar
。
这是我的空对话框布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/dialog_background">
<LinearLayout
android:id="@+id/testFragmentController"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="15dp"></LinearLayout>
</RelativeLayout>
这是第一个 fragment 的代码(我使用的是 android 注释):
@EFragment(R.layout.dialog)
public class FragmentGeneralDialog extends ClickDialogFragment {
@ViewById
LinearLayout testFragmentController;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
this.setStyle(R.style.Dialog_No_Border, getTheme());
return dialog;
}
@AfterViews
void afterViews() {
loadActivity();
GlobalData.setFragmentContainer(testFragmentController);
activity.loadMenuFragment(FragmentSocialDialog_.class, new SlideLeftAnimation());
}
}
loadMenuFragments(...)
是这样的:
public <T extends Fragment> T loadMenuFragment(final Class<T> cls,
final IAnimation a) {
T fragment = null;
try {
fragment = cls.newInstance();
} catch (Exception ex) {
throw new RuntimeException("Fragment " + cls.toString()
+ " has no empty constructor");
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
if (a != null) {
transaction.setCustomAnimations(a.getInId(), a.getOutId(), a.getInId(),
a.getOutId());
}
transaction.replace(R.id.testFragmentController, fragment);
try {
transaction.commit();
} catch (Exception e) {
}
return fragment;
}
最佳答案
您需要从对话框 fragment 中获取childFragmentManager
link ,然后您可以通过 getParentFragment().getChildFragmentManager()
关于android - 如何更改对话框 fragment 中的 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25475556/