Show Android DialogFragment as a dialogue in portrait mode and as part of activity in landscape mode

Is it possible to implement some kind of "self-managed" DialogFragment, which displays it as Dialog in portrait mode and as part of the activity in landscape mode. It will be very greedy if you present me the code

+6
source share
1 answer

Something like that:

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 operation I wrote that is just convenient for inserting a fragment dialog in an exercise, but basically you just need an activity that includes MyFragmentDialog. Here's the source of shell activity: https://github.com/jt-gilkeson/fragment-utils

0
source

Source: https://habr.com/ru/post/913542/


All Articles