Paint setAlpha - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Paint setAlpha method.

This code example shows how to use the following methods:setAlpha, setColor
 
            drawRects(canvas, Mode.XOR);
             
            canvas.translate(0.0f, 100.0f);
             
            mBluePaint.setAlpha(127);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 50.0f, mBluePaint);
             
            canvas.translate(0.0f, 100.0f);
             
            mBluePaint.setAlpha(10);
            mBluePaint.setColor(0x7f0000ff);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 50.0f, mBluePaint);
             
            mBluePaint.setColor(0xff0000ff);
            mBluePaint.setAlpha(255);
 
            canvas.restore();
        } 
 
        private void drawRects(Canvas canvas, PorterDuff.Mode mode) {
9
CodeRank
This code example shows how to use the following methods:setAlpha, setColor, setColorFilter, setTextSize
     * @see android.graphics.drawable.Drawable#draw( 
     *    android.graphics.Canvas) 
     */ 
    @Override 
    public void draw(Canvas canvas) {
        Paint paint = new Paint();
 
        paint.setColorFilter(filter);
        paint.setAlpha(opacity);
 
        paint.setTextSize(12);
        paint.setColor(Color.GREEN);
        canvas.drawText("Hello", 40, 55, paint);
 
        paint.setTextSize(16);
        paint.setColor(Color.RED);
        canvas.drawText("Android", 35, 65, paint);
    } 
 
    /** @see android.graphics.drawable.Drawable#getOpacity() */ 
    @Override 
8
CodeRank
This code example shows how to use the following methods:reset, setAlpha, setColor, setXfermode
8
CodeRank
This code example shows how to use the following methods:setAlpha, setAntiAlias, setColor, setFakeBoldText, setStyle
 
        init(); 
    } 
 
    private void init() { 
        mCirclePaint.setFakeBoldText(true);
        mCirclePaint.setAntiAlias(true);
        mCirclePaint.setColor(mCircleColor);
        mCirclePaint.setTextAlign(Align.CENTER);
        mCirclePaint.setStyle(Style.FILL);
        mCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
    } 
 
    public void drawIndicator(boolean drawCircle) {
        mDrawCircle = drawCircle;
    } 
 
    @Override 
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
8
CodeRank
This code example shows how to use the following methods:setAlpha, setColor
 
            drawRects(canvas, Mode.XOR);
             
            canvas.translate(0.0f, 100.0f);
             
            mBluePaint.setAlpha(127);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 50.0f, mBluePaint);
             
            canvas.translate(0.0f, 100.0f);
             
            mBluePaint.setAlpha(10);
            mBluePaint.setColor(0x7f0000ff);
            canvas.drawRect(0.0f, 0.0f, 50.0f, 50.0f, mBluePaint);
             
            mBluePaint.setColor(0xff0000ff);
            mBluePaint.setAlpha(255);
 
            canvas.restore();
        } 
 
        private void drawRects(Canvas canvas, PorterDuff.Mode mode) {
8
CodeRank
This code example shows how to use the following methods:setAlpha, setAntiAlias, setTextSize, setTypeface, getDesiredWidth
    ++n;
    return (n <= 0) ? 1 : n;
  } 
 
  private void prepareLayout() { 
    float desiredWidth = Layout.getDesiredWidth(text, paint);
 
    textWidth = (int)Math.ceil(desiredWidth);
    if (textWidth > maxWidthPixels) {
      textWidth = maxWidthPixels;
    } 
    else if (textWidth <= 0) {
      textWidth = 1;
    } 
 
    Layout.Alignment _alignment = Layout.Alignment.ALIGN_NORMAL;
 
    if (alignment == 1) {
      _alignment = Layout.Alignment.ALIGN_CENTER;
    } 

7
CodeRank
This code example shows how to use the following methods:setAlpha, setColor, setColorFilter, setTextSize
     * @see android.graphics.drawable.Drawable#draw( 
     *    android.graphics.Canvas) 
     */ 
    @Override 
    public void draw(Canvas canvas) {
        Paint paint = new Paint();
 
        paint.setColorFilter(filter);
        paint.setAlpha(opacity);
 
        paint.setTextSize(12);
        paint.setColor(Color.GREEN);
        canvas.drawText("Hello", 40, 55, paint);
 
        paint.setTextSize(16);
        paint.setColor(Color.RED);
        canvas.drawText("Android", 35, 65, paint);
    } 
 
    /** @see android.graphics.drawable.Drawable#getOpacity() */ 
    @Override 
8
CodeRank
This code example shows how to use the following methods:getColor, getStrokeWidth, setAlpha, setColor, setStyle
    private boolean mHighlightCenter;
 
    @Override  
    protected void onDraw(Canvas canvas) {
		float outer_radius = Math.min(getWidth(), getHeight())/2;
 		float touch_feedback_ring = center_radius + 2*mCenterPaint.getStrokeWidth();
        float r = (outer_radius + touch_feedback_ring) / 2;
         
        canvas.translate(getWidth()/2, getHeight()/2);
         
        mPaint.setStrokeWidth(outer_radius - touch_feedback_ring);
         
        // This is the main "color ring" 
        canvas.drawCircle(0, 0, r, mPaint);       
 
        // This is the center "activation button" circle 
        canvas.drawCircle(0, 0, center_radius, mCenterPaint);
         
        if (mTrackingCenter) {
            int c = mCenterPaint.getColor();

7
CodeRank
This code example shows how to use the following methods:setAlpha, setColor, setMaskFilter
    void applyOuterBlur(Bitmap bitmap, Canvas canvas, int color) {
        mBlurPaint.setMaskFilter(sThickOuterBlurMaskFilter);
        Bitmap glow = bitmap.extractAlpha(mBlurPaint, mTempOffset);
 
        // Use the clip table to make the glow heavier closer to the outline 
        mHolographicPaint.setMaskFilter(sCoarseClipTable);
        mHolographicPaint.setAlpha(150);
        mHolographicPaint.setColor(color);
 
        canvas.drawBitmap(glow, mTempOffset[0], mTempOffset[1], mHolographicPaint);
        glow.recycle();
    } 
 
    /** 
     * Applies a more expensive and accurate outline to whatever is currently drawn in a specified 
     * bitmap. 
     */ 
    void applyExpensiveOutlineWithBlur(Bitmap srcDst, Canvas srcDstCanvas, int color,
            int outlineColor, int thickness) {
        applyExpensiveOutlineWithBlur(srcDst, srcDstCanvas, color, outlineColor, mAlphaClipPaint,
7
CodeRank
This code example shows how to use the following methods:setAlpha, setColor, setStrokeWidth, setStyle

Related Paint setAlpha Questions & Answers:

setAlpha Method Overview
Helper to setColor(), that only assigns the color's alpha value, leaving its r,g,b values unchanged.
See Code Examples for other Android Paint Methods: