◎위챗 : speedseoul
http://howrobotswork.wordpress.com/2013/08/16/creating-a-fullscreen-dialogfragment-with-a-custom-background/
The default Dialogs (or rather the DialogFragments) look pretty good in Android since Honeycomb, but the Holo look-and-feel doesn’t go well together with all app designs. Not to mention sometimes you need a fully different layout, a custom background color, or a semitransparent background with no grey dimming at all. We’re talking about Android, where (almost) everything is possible, so there is a solution for this problem as well.
Customizing a DialogFragment is a quite easy task. Create a class extending DialogFragment, and override the onCreateDialog method, which is responsible for creating the Dialog. Instantiate a Dialog, then make the following calls on the instance:
These four steps give you an empty fullscreen layout to play with, with the option to add a semi-transparent background, revealing the underlying activity. From this point, only your imagination is the limit; a good example of what can be achieved is the following screen, taken from an upcoming app:
You can find more on using and customizing the DialogFragment at the official developer site. Here is a short sample code illustrating a DialogFragment with a yellow background and an empty layout.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | public class CustomDialogFragment extends DialogFragment { public CustomDialogFragment() {} @Override public Dialog onCreateDialog( final Bundle savedInstanceState) { // the content final RelativeLayout root = new RelativeLayout(getActivity()); root.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); // creating the fullscreen dialog final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(root); dialog.getWindow().setBackgroundDrawable( new ColorDrawable(Color.YELLOW)); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); return dialog; } } |