Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFragment in Android with theme

I'm building my first app in android. I've made a dialogFragment, but it doesn't look nice enough.For having a style and a theme I used this setStyle(DialogFragment.STYLE_NORMAL,0). What I want is that the edge of the fragment to be black like a frame, or have its corners round. I think I must write my own style in xml and put it in styles, but I'm not sure. Can someone point me to the right direction? Thank you for your time.

like image 512
Libathos Avatar asked Nov 20 '12 08:11

Libathos


People also ask

Is DialogFragment deprecated?

This class was deprecated in API level 28.

How do I display DialogFragment?

Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.

What is the difference between dialog and DialogFragment?

Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.

What is DialogFragment used for?

DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.


1 Answers

As you say you'll need to create the style that you want to apply, and then assign it to your DialogFragment as the second parameter in the setStyle() method call. You must remember to make this call before you call show().

So, if you create a new style named "MyStyle" in res/values/styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    .
    .
    .
    <style name="MyStyle">
        .
        .
        .
    </style>
    .
    .
    .
</resources>

Then use this in your setStyle call:

DialogFragment dial = (DialogFragment) Fragment.instantiate(this, MyDialogFragment.class.getCanonicalName());
dial.setStyle( DialogFragment.STYLE_NORMAL, R.style.MyStyle );
dial.show();
like image 162
Mark Allison Avatar answered Sep 20 '22 21:09

Mark Allison