Skip to content

Instantly share code, notes, and snippets.

@jie-meng
Created October 11, 2017 14:29
Show Gist options
  • Save jie-meng/a1c6cbbba2100c530c15add45447f653 to your computer and use it in GitHub Desktop.
Save jie-meng/a1c6cbbba2100c530c15add45447f653 to your computer and use it in GitHub Desktop.
Apply dim to Activity
public static void applyDim(@NonNull Activity activity){
float dimAmount = 0.5f;
ViewGroup rootView = (ViewGroup) (activity.getWindow().getDecorView().getRootView());
Drawable dim = new ColorDrawable(Color.BLACK);
dim.setBounds(0, 0, rootView.getWidth(), rootView.getHeight());
dim.setAlpha((int) (255 * dimAmount));
ViewGroupOverlay overlay = rootView.getOverlay();
overlay.add(dim);
}
public static void clearDim(@NonNull Activity activity) {
ViewGroup rootView = (ViewGroup) (activity.getWindow().getDecorView().getRootView());
ViewGroupOverlay overlay = rootView.getOverlay();
overlay.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment