rgb值如下 第一种:r=199, g=237, b=204; 第一种:r=129, g=116, b=38;
效果图如下
第一步:动态添加一个透明的帧布局且设置此布局不可触不可定焦
protected void initEyeView() {
ViewGroup content = ((ViewGroup) findViewById(android.R.id.content));
view = new FrameLayout(this);
view.setBackgroundColor(Color.TRANSPARENT); //设置透明
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL //不触碰
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE //不可定焦
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; //不可触
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.MATCH_PARENT;
content.addView(view, params);
}
第二步:设置颜色的方法,由于要考虑透明度所以使用Color.argb()方法
public int getFilterColor() {
//第一种
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);
}
第三步:给帧布局上色
public void openEye() {
view.setBackgroundColor(getFilterColor());
}
另外关闭护眼模式:将帧布局设置为透明
public void closeEye() {
view.setBackgroundColor(Color.TRANSPARENT);
}
如需要整个app都起效果,在BaseActivity中调用即可。