美文网首页
Android工作整理-国难日灰度显示

Android工作整理-国难日灰度显示

作者: zhongcx | 来源:发表于2020-05-31 11:12 被阅读0次
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation( 0);//0:表示灰度显示,1:表示彩色显示
paint.setColorFilter(new ColorMatrixColorFilter(cm));
view.setLayerType(View.LAYER_TYPE_HARDWARE, paint);

特点:
【1】会对 子view 也灰度显示
【2】支持webview中的网页灰度显示
【3】Activity中拿到全局view的方法是getWindow().getDecorView()

    @Override
    protected void onCreate(Bundle savedInstanceState, int layoutResID) {
        super.onCreate(savedInstanceState, R.layout.layout_main);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);//0:表示灰度显示,1:表示彩色显示
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        getWindow().getDecorView().setLayerType(View.LAYER_TYPE_HARDWARE, paint);
    }

【4】Fragment中拿到全局view的方法是onCreateView中的return view;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View contentView = inflater.inflate(R.layout.fragment_main_my, container, false);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);//0:表示灰度显示,1:表示彩色显示
        paint.setColorFilter(new ColorMatrixColorFilter(cm));
        contentView.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
        return contentView;
    }

相关文章

网友评论

      本文标题:Android工作整理-国难日灰度显示

      本文链接:https://www.haomeiwen.com/subject/wqelzhtx.html