avast / android-styled-dialogs

Backport of Material dialogs with easy-to-use API based on DialogFragment
Apache License 2.0
2.15k stars 450 forks source link

Dark theme in custom dialog #112

Closed massimobio closed 9 years ago

massimobio commented 9 years ago

Is it possible to set the dark theme when making a custom dialog like in the JayneHatDialogFragment example?

davidvavra commented 9 years ago

Of course, either use global dark theme or method useDarkTheme()

massimobio commented 9 years ago

Sorry, I should have phrased my question better: How do I set the custom builder to use the dark theme?

To show a simple dialog fragment from an activity I set the dark theme like this: SimpleDialogFragment.createBuilder(this, getSupportFragmentManager()).setTitle("Title").setPositiveButtonText(R.string.ok).useDarkTheme().show();

To show a custom dialog fragment from an activity I do this: JayneHatDialogFragment.show(this); Here I cannot set the dark theme.

In my custom class I wasn't able to set the dark theme in the overridden builder: @Override public BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) {... because the builder here is not a BaseDialogBuilder.

massimobio commented 9 years ago

I solved it by adding the dark theme argument to the bundle in my custom view. Not the cleanest solution but it works.

public static void show(FragmentActivity activity) {
    JayneHatDialogFragment dialog = new JayneHatDialogFragment ();
    Bundle args = new Bundle();
    args.putBoolean(BaseDialogBuilder.ARG_USE_DARK_THEME, true);
    dialog.setArguments(args);
    dialog.show(activity.getSupportFragmentManager(), TAG);
}