DialogFragment in Android with theme

后端 未结 1 620
臣服心动
臣服心动 2021-01-01 16:13

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

相关标签:
1条回答
  • 2021-01-01 16:51

    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();
    
    0 讨论(0)
提交回复
热议问题