Android VideoView: Video view is much darker in a dialog view-ThrowExceptions

Exception or error:

Hi all
I have a problem with embedding a video view inside a dialog view

everything works fine except that the video displayed in the Dialog is much darker that if displayed in the rest of the activity

any ideas ?

here is some code

button1main.setOnClickListener(new OnClickListener() {

                public VideoView videoView = null;
                public void onClick(View v) {
                    //set up dialog
                    Dialog dialog = new Dialog(CustomDialog.this);
                    //dialog.setTitle("This is my custom dialog box");

                    this.videoView = (VideoView) dialog.findViewById(;
                    VideoPlayer vp = new VideoPlayer(this.videoView, null);

                    //set up button
                    Button button = (Button) dialog.findViewById(;
                    button.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                    //now that the dialog is set up, it's time to show it    
How to solve:

it seems that the VideoView gets dimmed because it is created behind the window.
Jason Rogers solution works but means that the area behind the dialog will not get dimmed.

I used


to bring the VideoView to front, so that it does not get dimmed, but still everything behind the dialog will.


I actually found the solution to this (or at least in my case)

it seems its a bug from android where the Video View is created behind the Dialog and when the Dialog opens it dims the background views including the video

the “quick fix” I applied is

WindowManager.LayoutParams a = dialog.getWindow().getAttributes();
a.dimAmount = 0;

they might be a solution better solution like passing the context of the Dialog box instead of using the same context for creating the Dialog and the Video View (I’ll check later if I get sone time)


While the spatialist suggested works, the only problem there is if you ever want to setZOrderOnTop to false after setting it to true. It seems once set it is always true.

I recently came across the same issue (videoview in a dialog) and the way I fixed it, reluctantly, was to clear FLAG_DIM_BEHIND so the video is “bright”. I got the dim effect by just making my dialog fullscreen and setting the background to a ‘dim color’ if that makes any sense.

More Info:
With regards to the media controller, I could not find any way of bringing it to top of the dialog. I ended up creating a custom media controls layout and put it on top of the video view. It’s important in this context as calling setZOrderOnTop would prevent you from putting the media controller on top of the video view.

Hope this made sense and helps someone.


I tried this fix and found it working.

Use following style on the dialog for removing the default dim behavior of the Window, so the VideoView / SurfaceView doesn’t have the dim behavior as well.

<item name="android:backgroundDimEnabled">false</item>

Then in the dialog’s onViewCreated method, set the background programmatically to achieve the Dim effect.



one more simple solution is add this to your styles, it will disable dim background.

<item name="android:backgroundDimEnabled">false</item>

Leave a Reply

Your email address will not be published. Required fields are marked *