Created
February 17, 2020 07:55
-
-
Save naufalnibros/b8f1a9a0b9181ba85777b60f8d011cfa to your computer and use it in GitHub Desktop.
Android Studio Java - Fullscreen Dialog Fragment with Status Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FullScreenDialogFragment extends DialogFragment { | |
| public FullScreenDialogFragment() { | |
| } | |
| @Override | |
| public void onCreate(@Nullable Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme); | |
| } | |
| @Override | |
| public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
| return inflater.inflate(R.layout.fragment_fullscreen_dialog, container, false); | |
| } | |
| @NonNull | |
| @Override | |
| public Dialog onCreateDialog(Bundle savedInstanceState) { | |
| Dialog dialog = super.onCreateDialog(savedInstanceState); | |
| Objects.requireNonNull(dialog.getWindow()).setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN); | |
| dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE)); | |
| return dialog; | |
| } | |
| @Override | |
| public void onStart() { | |
| super.onStart(); | |
| Dialog dialog = getDialog(); | |
| if (dialog != null) { | |
| int width = ViewGroup.LayoutParams.MATCH_PARENT; | |
| int height = ViewGroup.LayoutParams.MATCH_PARENT; | |
| Objects.requireNonNull(dialog.getWindow()).setLayout(width, height); | |
| dialog.setCancelable(false); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <resources> | |
| <!-- Base application theme. --> | |
| <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | |
| <item name="android:windowActionBar">false</item> | |
| <item name="android:windowNoTitle">true</item> | |
| <item name="android:windowDisablePreview">true</item> | |
| <item name="colorPrimary">@color/colorPrimary</item> | |
| <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | |
| <item name="colorAccent">@color/colorAccent</item> | |
| </style> | |
| </resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment