Dim window when menu is open in Android

On Android, when a warning appears, the background is darkened. I would like to get a similar effect when opening a menu. I tried the following code but it didn't work:

@Override
public boolean onMenuOpened(int featureId, Menu m) {
    boolean ret=super.onMenuOpened(featureId,m);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    return ret;
}

      

Does anyone know how to achieve this?

+2


a source to share


1 answer


Typically you set this flag when you have a new activity that uses the ThemeDialog - this renders the dialog with the previous activity still visible, and in the case of FLAG_DIM_BEHIND, dimmed.



FLAG_DIM_BEHIND means that your current activity will be visible and have normal brightness, and the previous activity that is still visible (if you are using ThemeDialog) will be dimmed. I'm not sure if you can use this flag for your own purposes.

+1


a source







All Articles