3

I saw this question and also this one and some others, but nothing really helped me.

I'm building a quick action DialogFragment for my list view and trying to set a custom view to it according to the android dev guide.

view_quick_action.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/white" >

    <ImageView
        android:id="@+id/quick_action_image"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_margin="20dp"
        android:scaleType="fitXY"
        android:src="@drawable/windows1" />

    <TextView
        android:id="@+id/quick_action_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/quick_action_image"
        android:layout_toRightOf="@+id/quick_action_image"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="Lilly"
        android:textColor="#585858"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/quick_action_activity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/quick_action_image"
        android:layout_toRightOf="@+id/quick_action_image"
        android:text="Updated 4 minutes ago"
        android:textColor="#a3a3a3"
        android:textSize="15sp" />

    <ImageButton
        android:id="@+id/popup_grid_leave"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/quick_action_activity"
        android:layout_margin="20dp"
        android:layout_marginTop="30dp"
        android:background="@color/transperent"
        android:src="@drawable/ic_action_leave" />

    <ImageButton
        android:id="@+id/popup_grid_silence"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@+id/popup_grid_leave"
        android:layout_alignTop="@+id/popup_grid_leave"
        android:layout_centerHorizontal="true"
        android:background="@color/transperent"
        android:src="@drawable/ic_action_silence" />

    <ImageButton
        android:id="@+id/popup_grid_mark_as_read"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@+id/popup_grid_leave"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/popup_grid_leave"
        android:layout_marginRight="15dp"
        android:background="@color/transperent"
        android:src="@drawable/ic_action_mark_as_read" />

</RelativeLayout>

QuickActionFragment.java

public class QuickActionFragment extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

        View v = LayoutInflater.from(mContext).inflate(
        R.layout.view_quick_action, null, false);

        // SET ALL THE VIEWS

        builder.setTitle(null);

        AlertDialog dialog = builder.create();
        dialog.setView(v, 0, 0, 0, 0);
        // this line didn't change anything
        // dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

        return dialog;
    }
}

after all this, when I run dialogFragment.show(getSupportedFragmentManager()) I still get the black border as shown in the image: quickActionImage

any thoughts on how to fix this?

Community
  • 1
  • 1
thepoosh
  • 12,497
  • 15
  • 73
  • 132

4 Answers4

11

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

rsicarelli
  • 1,013
  • 1
  • 11
  • 28
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • I should show the dialog in `onCreateDialog` instead of in the calling code?! – thepoosh Feb 07 '13 at 09:01
  • this didn't work, I added a `style` with those params and nothing changed – thepoosh Feb 07 '13 at 11:22
  • 2
    your code is supported only starting at API lvl 11, I'm supporting all the way down to 9 – thepoosh Feb 07 '13 at 11:42
  • I have only changed the AlertDialog to Dialog in your code nothing else than that. So there should not be any issue for the API level. I guess so.. What error you have let me know. – GrIsHu Feb 07 '13 at 12:25
  • the constructor that takes 2 arguments is from API 11 and above as can be seen here: http://tinyurl.com/b9jg6ht – thepoosh Feb 07 '13 at 13:08
1

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.

  • Thanks, this line of code was the answer I was looking for: Dialog.Window.SetBackgroundDrawableResource(Resource.Color.transparent); – Josue Morales Nov 04 '21 at 22:26
0

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.

Wild Fire
  • 61
  • 1
  • 5
0

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);
ono
  • 2,984
  • 9
  • 43
  • 85