0

I have a DialogFragment (from android.support.v4.app.DialogFragment) where the activity behind dims perfectly as expected on my Android 5.1 (Lollipop). But on Kitkat, the dimming does not work.

I tried the following solutions but failed:

  1. Android Dim Background of Custom Dialog
  2. DialogFragment with clear background (not dimmed)

Am I missing something? TIA.

EDIT 1:

This is my onCreateDialog method of the DialogFragment.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View layout = inflater.inflate(R.layout.fragment_dialog, null);
    ...
    // set textfield listeners here
    ...
    builder.setView(layout);
    return builder.create();
}

Here is my DialogFragment layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">
    ...
</LinearLayout>

As you can see, I am not doing anything special in my layout xml.

And this is how I call the dialog up:

MyDialogFragment dialog = new MyDialogFragment();
dialog.setListener(this);
dialog.setCallingActivity(this);
FragmentManager fm = getSupportFragmentManager();
dialog.show(fm, "MyDialogFragment");
user1506104
  • 6,554
  • 4
  • 71
  • 89
  • Can you show us your XML layouts and at least the `onCreateView` and/or `onCreateDialog` methods in your DialogFragment, as well as how the dialog is invoked from the activity? – AGDownie Nov 14 '18 at 17:14
  • Updated. I am not doing anything special in any of my source codes. This works perfectly fine on my Lollipop device. – user1506104 Nov 14 '18 at 17:50
  • That looks perfectly normal. Using the same code (minus your custom `setListener()` `setCallingActivty()` calls) does show a dimmed background on my tablet running KitKat 4.4.2. May be something specific to 4.4.4 or your device-specific Android build. – AGDownie Nov 14 '18 at 20:12

1 Answers1

0

I was not able to fix the dim issue on Android 4.4.4. The best result that I got was from this dialog:

enter image description here

into this nicer dialog with elevation

enter image description here

To do this, simply use this import of the DialogFragment:

import android.app.DialogFragment;

Finally, of course, use the proper FragmentManager:

FragmentManager fm = getFragmentManager();

Cheers!

user1506104
  • 6,554
  • 4
  • 71
  • 89