Introduction: Eye protection mode can be said to add a layer of a certain color and the transparency is less than 1 view, now on the network more popular eye color bloggers prefer the following two.

RGB values as follows

  • R =199, g=237, b=204;
  • R =129, g=116, b=38;

The renderings are as follows

Step 1: Dynamically add a transparent frame layout and set the layout out of touch and focus

ViewGroup content = ((ViewGroup) findViewById(android.R.id.content)); view = new FrameLayout(this); view.setBackgroundColor(Color.TRANSPARENT); / / set transparent WindowManager. LayoutParams params = new WindowManager. LayoutParams (); Params. Flags = WindowManager. LayoutParams. FLAG_NOT_TOUCH_MODAL / / don't touch | WindowManager. LayoutParams. FLAG_NOT_FOCUSABLE / / not fixed focus | WindowManager. LayoutParams. FLAG_NOT_TOUCHABLE; / / do not touch the params. Width = WindowManager. LayoutParams. MATCH_PARENT; params.height = WindowManager.LayoutParams.MATCH_PARENT; content.addView(view, params); }Copy the code

Step 2: Set the Color method, using the color.argb () method for transparency

    public int getFilterColor() {// first type int a = (int) (67.5); int r = (int) (199); int g = (int) (237); int b = (int) (204); // int a = (int) (67.5); Int r = (int) (129); // int g = (int) (116); // int b = (int) (38);return Color.argb(a, r, g, b);
    }
Copy the code

Step 3: Color the frame layout

public void openEye() {
    view.setBackgroundColor(getFilterColor());
}
Copy the code

Also turn off eye protection mode: set the frame layout to transparent

  public void closeEye() {
        view.setBackgroundColor(Color.TRANSPARENT);
    }
Copy the code

If you want the entire app to work, just call it in BaseActivity.