I am trying to show an activity as a floating window with a dimmed background and I'm using the following code to do that, which is taken from the Google I/O 2016 project:
protected void setupFloatingWindow(int width, int height, int alpha, float dim) {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.width = getResources().getDimensionPixelSize(width);
params.height = getResources().getDimensionPixelSize(height);
params.alpha = alpha;
params.dimAmount = dim;
params.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
getWindow().setAttributes(params);
}
I am calling this function in onCreate, before super.onCreate and setContentView , as it is in the Google I/O example code.
This way it doesn't work for me. The activity is shown as a floating window, with the size that I am setting, but the background behind is black and not dimmed as I expect it to be. The dimAmount that I am setting is 0.4f.
Am I missing something? Should I add something more? Please help