本文整理汇总了Java中android.graphics.Paint.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.setColor方法的具体用法?Java Paint.setColor怎么用?Java Paint.setColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Paint
的用法示例。
在下文中一共展示了Paint.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addArrowView
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* Adds an arrow view pointing at the original icon.
* @param horizontalOffset the horizontal offset of the arrow, so that it
* points at the center of the original icon
*/
private View addArrowView(int horizontalOffset, int verticalOffset, int width, int height) {
LayoutParams layoutParams = new LayoutParams(width, height);
if (mIsLeftAligned) {
layoutParams.gravity = Gravity.START;
layoutParams.leftMargin = horizontalOffset;
} else {
layoutParams.gravity = Gravity.END;
layoutParams.rightMargin = horizontalOffset;
}
if (mIsAboveIcon) {
layoutParams.topMargin = verticalOffset;
} else {
layoutParams.bottomMargin = verticalOffset;
}
View arrowView = new View(getContext());
if (Gravity.isVertical(((FrameLayout.LayoutParams) getLayoutParams()).gravity)) {
// This is only true if there wasn't room for the container next to the icon,
// so we centered it instead. In that case we don't want to show the arrow.
arrowView.setVisibility(INVISIBLE);
} else {
ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
width, height, !mIsAboveIcon));
Paint arrowPaint = arrowDrawable.getPaint();
// Note that we have to use getChildAt() instead of getItemViewAt(),
// since the latter expects the arrow which hasn't been added yet.
PopupItemView itemAttachedToArrow = (PopupItemView)
(getChildAt(mIsAboveIcon ? getChildCount() - 1 : 0));
arrowPaint.setColor(itemAttachedToArrow.getArrowColor(mIsAboveIcon));
// The corner path effect won't be reflected in the shadow, but shouldn't be noticeable.
int radius = getResources().getDimensionPixelSize(R.dimen.popup_arrow_corner_radius);
arrowPaint.setPathEffect(new CornerPathEffect(radius));
arrowView.setBackground(arrowDrawable);
arrowView.setElevation(getElevation());
}
addView(arrowView, mIsAboveIcon ? getChildCount() : 0, layoutParams);
return arrowView;
}
示例2: init
import android.graphics.Paint; //导入方法依赖的package包/类
private void init() {
setLayerType(LAYER_TYPE_SOFTWARE,null);
mPaint = new Paint();
mPaint.setStyle(Paint.Style.FILL);
mPaint.setStrokeWidth(1);
mPaint.setAntiAlias(true);
mPaint.setColor(Color.RED);
mPath = new Path();
anim = ValueAnimator.ofFloat(0f,1f);
anim.setInterpolator(new AccelerateInterpolator());
anim.setDuration(5000);
anim.setRepeatCount(ValueAnimator.INFINITE);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
progress = (float)animation.getAnimatedValue();
invalidate();
}
});
anim.start();
}
示例3: cropCircle
import android.graphics.Paint; //导入方法依赖的package包/类
public Bitmap cropCircle(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2,
bitmap.getWidth() / 2, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例4: drawHrozontal
import android.graphics.Paint; //导入方法依赖的package包/类
private void drawHrozontal(Canvas c, RecyclerView parent) {
int childCount = parent.getChildCount();
if (childCount<1)return;
// int left = parent.getPaddingLeft()+leftView.getLeft()+leftView.getPaddingLeft();
int top = parent.getPaddingTop();
int bottom = parent.getHeight() - parent.getPaddingBottom();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.LTGRAY);
for (int i = 0; i < childCount-1; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
.getLayoutParams();
int left = child.getRight()+params.rightMargin;
int right = left + 1;
c.drawRect(left, top, right, bottom, paint);
}
}
示例5: drawTimeLabels
import android.graphics.Paint; //导入方法依赖的package包/类
public void drawTimeLabels(Canvas canvas) {
int px = rulerStartX;
py = TIME_LABEL_FONT_SIZE + TIME_LABEL_VERTICAL_PADDING;
Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setTextSize(TIME_LABEL_FONT_SIZE);
mTextPaint.setColor(Color.LTGRAY);
for (int i = 0; i < totalHours; i++) {
String displayText = String.format("%02d:00", initialHour + i);
float textWidth = mTextPaint.measureText(displayText);
canvas.drawText(displayText, px, py, mTextPaint);
labelXPosition[i] = px;
px += textWidth + 10;
}
viewWidth = px;
py += TIME_LABEL_VERTICAL_PADDING;
canvas.drawLine(0, py, viewWidth, py, mTextPaint);
}
示例6: init
import android.graphics.Paint; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs) {
mContext = context;
TypedArray ta = mContext.getTheme().obtainStyledAttributes(attrs,R.styleable.RingChartView,0,0);
mChartRadius = ta.getDimension(R.styleable.RingChartView_bigRingRadius,DEFAULT_RING_RADIUS);
mCenterRadius = ta.getDimension(R.styleable.RingChartView_smallCircleRadius,DEFAULT_CENTER_RADIUS);
mTextSize =ta.getDimension(R.styleable.RingChartView_ringTextSize,DEFAULT_TEXTSIZE);
ta.recycle();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.FILL);
textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextSize(mTextSize);
textPaint.setColor(mTextColor);
wcPath = new Path();
}
示例7: BorderedText
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* Create a bordered text object with the specified interior and exterior colors, text size and
* alignment.
*
* @param interiorColor the interior text color
* @param exteriorColor the exterior text color
* @param textSize text size in pixels
*/
public BorderedText(final int interiorColor, final int exteriorColor, final float textSize) {
interiorPaint = new Paint();
interiorPaint.setTextSize(textSize);
interiorPaint.setColor(interiorColor);
interiorPaint.setStyle(Style.FILL);
interiorPaint.setAntiAlias(false);
interiorPaint.setAlpha(255);
exteriorPaint = new Paint();
exteriorPaint.setTextSize(textSize);
exteriorPaint.setColor(exteriorColor);
exteriorPaint.setStyle(Style.FILL_AND_STROKE);
exteriorPaint.setStrokeWidth(textSize / 8);
exteriorPaint.setAntiAlias(false);
exteriorPaint.setAlpha(255);
this.textSize = textSize;
}
示例8: initPaints
import android.graphics.Paint; //导入方法依赖的package包/类
private void initPaints() {
paintOuterText = new Paint();
paintOuterText.setColor(textColorOut);
paintOuterText.setAntiAlias(true);
paintOuterText.setTypeface(Typeface.MONOSPACE);
paintOuterText.setTextSize(textSize);
paintCenterText = new Paint();
paintCenterText.setColor(textColorCenter);
paintCenterText.setAntiAlias(true);
paintCenterText.setTextScaleX(1.1F);
paintCenterText.setTypeface(Typeface.MONOSPACE);
paintCenterText.setTextSize(textSize);
paintIndicator = new Paint();
paintIndicator.setColor(dividerColor);
paintIndicator.setAntiAlias(true);
if (android.os.Build.VERSION.SDK_INT >= 11) {
setLayerType(LAYER_TYPE_SOFTWARE, null);
}
}
示例9: otherInit
import android.graphics.Paint; //导入方法依赖的package包/类
private void otherInit() {
// Other initialization
mBlackPaint = new Paint();
mBlackPaint.setColor(0xff000000);
mMaskedPaint = new Paint();
mMaskedPaint
.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
// Always want a cache allocated.
mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
if (mDesaturateOnPress) {
// Create a desaturate color filter for pressed state.
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
}
}
示例10: draw
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top,
int y, int bottom, @NonNull Paint paint) {
RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);
Paint rectPaint = new Paint(paint);
rectPaint.setAntiAlias(true);
rectPaint.setStrokeWidth(2);
rectPaint.setStyle(Paint.Style.STROKE);
rectPaint.setColor(color);
canvas.drawRect(rect, rectPaint);
canvas.drawText(text, start, end, x, y, paint);
}
示例11: drawPath2
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 画线 一天线
*
* @param canvas
*/
private void drawPath2(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
Path path = new Path();
path.lineTo(100, 100);
path.rLineTo(100, 0); //r 是相对路径 意思是从上次的(100,100)为起点,相对来说画一条向右 100 的直线
path.quadTo(100, 100, 500, 500);
canvas.drawPath(path, paint);
}
示例12: toRoundCorner
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* 转为圆角图片
*
* @param src 源图片
* @param radius 圆角的度数
* @param borderSize 边框尺寸
* @param borderColor 边框颜色
* @param recycle 是否回收
* @return 圆角图片
*/
public static Bitmap toRoundCorner(final Bitmap src, final float radius, int borderSize, int borderColor, final boolean recycle) {
if (isEmptyBitmap(src)) {
return null;
}
int width = src.getWidth();
int height = src.getHeight();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Bitmap ret = Bitmap.createBitmap(width, height, src.getConfig());
BitmapShader shader = new BitmapShader(src, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
Canvas canvas = new Canvas(ret);
RectF rectF = new RectF(0, 0, width, height);
float halfBorderSize = borderSize / 2f;
rectF.inset(halfBorderSize, halfBorderSize);
canvas.drawRoundRect(rectF, radius, radius, paint);
if (borderSize > 0) {
paint.setShader(null);
paint.setColor(borderColor);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(borderSize);
paint.setStrokeCap(Paint.Cap.ROUND);
canvas.drawRoundRect(rectF, radius, radius, paint);
}
if (recycle && !src.isRecycled()) {
src.recycle();
}
return ret;
}
示例13: SpringBar
import android.graphics.Paint; //导入方法依赖的package包/类
public SpringBar(Context context, int springColor, float maxRadiusPercent, float minRadiusPercent) {
super(context);
this.maxRadiusPercent = maxRadiusPercent;
this.minRadiusPercent = minRadiusPercent;
foot = new Point();
head = new Point();
path = new Path();
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(1);
paint.setColor(springColor);
}
示例14: transform
import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
// Prepare the background
Paint paintBg = new Paint();
paintBg.setColor(BORDER_COLOR);
paintBg.setAntiAlias(true);
// Draw the background circle
canvas.drawCircle(r, r, r, paintBg);
// Draw the image smaller than the background so a little border will be seen
canvas.drawCircle(r, r, r - BORDER_RADIUS, paint);
squaredBitmap.recycle();
return bitmap;
}
示例15: initEntityBorder
import android.graphics.Paint; //导入方法依赖的package包/类
private void initEntityBorder(@NonNull MotionEntity entity ) {
// init stroke
int strokeSize = getResources().getDimensionPixelSize(R.dimen.scribble_stroke_size);
Paint borderPaint = new Paint();
borderPaint.setStrokeWidth(strokeSize);
borderPaint.setAntiAlias(true);
borderPaint.setColor(getContext().getResources().getColor(R.color.sticker_selected_color));
entity.setBorderPaint(borderPaint);
}