Created
October 11, 2017 14:29
-
-
Save jie-meng/a1c6cbbba2100c530c15add45447f653 to your computer and use it in GitHub Desktop.
Apply dim to Activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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