DialogFragment remove black border

只谈情不闲聊 提交于 2019-11-30 23:56:16
GrIsHu

Try out below code:

public class QuickActionFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog m_dialog = new Dialog(QuickActionFragment.this, R.style.Dialog_No_Border);
        LayoutInflater m_inflater = LayoutInflater.from(CustomDialogActivity.this);
        View v = LayoutInflater.from(mContext).inflate(R.layout.view_quick_action, null, false);
        // SET ALL THE VIEWS
        m_dialog.setTitle(null);
        m_dialog.setContentView(m_view);
        m_dialog.show();
        return dialog;
    }
}

Add the Dialog_No_Border style in your res/value/style.xml file.

<style name="Dialog_No_Border">
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

This style causes R to be deleted after a clean

Try to use setStyle(style, theme) method, when create your instance, like this:

public static YourDialog newInstance() {
    YourDialog frag = new YourDialog();
    // your code
    frag.setStyle(DialogFragment.STYLE_NO_FRAME, 0);
    // your code
    return frag;
}

I hope this help.

I couldn't get any of the answers to work on Gingerbread since the top and bottom were getting cut-off, but I found a workaround: You can set extra padding at the top and bottom to offset the cut-off.

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    int padding = getResources().getDimensionPixelSize(R.dimen.your_padding);
    view.setPadding(0, padding, 0, padding);
}

then set the view as prescribed by the other answers

demoDialog.setView(view, 0, 0, 0, 0);

I couldn't get any of these work on Xamarin - Android. Maybe this solution can save some time to someone out there:

public override void OnCreate(Bundle savedInstanceState)
{
    base.OnCreate(savedInstanceState);
    SetStyle(DialogFragmentStyle.NoFrame, 0);
}

public override void OnResume()
{
    base.OnResume();
    Dialog.Window.SetBackgroundDrawableResource(Resource.Color.transparent);
}

If you don't have color 'transparent' in resources, you can create it or use the default from Android. I had this issue while customising the dialog fragment of the MvvmCross Fingerprint Plugin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!