Android examples for Graphics:Canvas
fill Rect on Canvas
/*/*w w w . j a v a2s. c om*/ * Copyright 2016 Anteros Tecnologia * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ //package com.java2s; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; public class Main { private static Paint paint = new Paint(); public static void fillRect(Canvas canvas, int left, int top, int right, int bottom, boolean drawBorder, int fillColor, int borderColor, float borderSize) { if (borderSize == 0) borderSize = 0.5f; paint.setAntiAlias(true); paint.setStyle(Paint.Style.FILL); canvas.save(); canvas.clipRect(new Rect(left, top, right, bottom)); if (drawBorder) { paint.setColor(borderColor); canvas.drawRect(left, top, right, bottom, paint); paint.setColor(fillColor); canvas.drawRect(left + borderSize, top + borderSize, right - (borderSize * 2), bottom - (borderSize * 2), paint); } else { paint.setColor(fillColor); canvas.drawRect(left, top, right, bottom, paint); } canvas.restore(); } public static void fillRect(Canvas canvas, Rect rect, boolean drawBorder, int fillColor, int borderColor, float borderSize) { fillRect(canvas, rect.left, rect.top, rect.right, rect.bottom, drawBorder, fillColor, borderColor, borderSize); } }