利用Paint的 setColorFilter 顏色過濾 來實現按鈕被按下的效果
阿新 • • 發佈:2019-02-02
private boolean isGrayMode = false; public void setGrayMode(boolean bFlag) { if(isGrayMode == bFlag) { return; } if(bFlag) { cmcf = paint.getColorFilter(); // 灰度色矩陣 ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.setSaturation(0); ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter( colorMatrix); paint.setColorFilter(colorMatrixFilter); } else { paint.setColorFilter(cmcf); } isGrayMode = bFlag; }
效果圖
colorMatrix.setSaturation(X);
1 0.5 0