Is it possible to implement some kind of "self-managed" DialogFragment that display itslef like Dialog in portrait mode and like part of activity in landscape mode. It will be very greate if you present me with some code
是否可以实现某种“自我管理”的DialogFragment,它在纵向模式下显示像Dialog,并且在横向模式下显示活动的一部分。如果你给我提供一些代码,那将非常有用
1 个解决方案
#1
0
Something like this:
像这样的东西:
Activity activity = getActivity();
int orientation = activity.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// Start DialogFragment as dialog
MyFragmentDialog frag = new MyFragmentDialog();
frag.show(getFragmentManager(), "dialog");
}
else
{
// Start activity that embeds DialogFragment
Intent intent = new SimpleFragmentActivity.IntentBuilder(activity, MyFragmentDialog.class)
.create();
activity.startActivity(intent);
}
SimpleFragmentActivity
is a wrapper activity I wrote that simply embeds the fragment dialog in an activity for convenience, but basically you just need an activity that embeds MyFragmentDialog in it. Here's the source for the wrapper activity: https://github.com/jt-gilkeson/fragment-utils
SimpleFragmentActivity是我编写的一个包装器活动,它只是为了方便而将片段对话框嵌入到一个活动中,但基本上你只需要一个在其中嵌入MyFragmentDialog的活动。以下是包装器活动的来源:https://github.com/jt-gilkeson/fragment-utils
#1
0
Something like this:
像这样的东西:
Activity activity = getActivity();
int orientation = activity.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE)
{
// Start DialogFragment as dialog
MyFragmentDialog frag = new MyFragmentDialog();
frag.show(getFragmentManager(), "dialog");
}
else
{
// Start activity that embeds DialogFragment
Intent intent = new SimpleFragmentActivity.IntentBuilder(activity, MyFragmentDialog.class)
.create();
activity.startActivity(intent);
}
SimpleFragmentActivity
is a wrapper activity I wrote that simply embeds the fragment dialog in an activity for convenience, but basically you just need an activity that embeds MyFragmentDialog in it. Here's the source for the wrapper activity: https://github.com/jt-gilkeson/fragment-utils
SimpleFragmentActivity是我编写的一个包装器活动,它只是为了方便而将片段对话框嵌入到一个活动中,但基本上你只需要一个在其中嵌入MyFragmentDialog的活动。以下是包装器活动的来源:https://github.com/jt-gilkeson/fragment-utils