N Sharma
N Sharma

Reputation: 34497

Set the surface view border color

I want to set the surface view border color. When i set this this surface view color then it cover entire by that color. It hide my video which run in the surface view.

surfaceView = new SurfaceView(context);
surfaceView.setPadding(20, 20, 20, 20);
surfaceView.setBackgroundColor(Color.MAGENTA);

I tried this also

surfaceView = new SurfaceView(context) {
    @Override
    protected void onDraw(Canvas canvas){
        canvas.drawColor(Color.MAGENTA);
        Rect border = new Rect(20, 20, surfaceView.getWidth() - 20, surfaceView.getHeight() - 20);
        Paint paint = new Paint();
        paint.setStrokeWidth(10);
        paint.setColor(Color.MAGENTA);
        canvas.drawRect(border, paint);
    }
};
surfaceView.setPadding(50, 50, 50, 50);

I tried this also but still its there is no border on it.

Please help me to set the surface view border color.

Thanks in advance.

Upvotes: 1

Views: 2696

Answers (1)

WarrenFaith
WarrenFaith

Reputation: 57672

Have you tried to use canvas.drawColor(Color.BLACK); in your surface view? The Canvas itself shouldn't cover the padding area and therefor you have your border.

Other solution would be to draw the border yourself:

// untested - written out of memory
onDraw(Canvas canvas) {
    canvas.drawColor(Color.BLACK);
    Rect border = new Rect(10, 10, width - 10, height - 10);
    mPaint.setLineWidth(10);
    mPaint.setColor(Color.MAGENTA);
    canvas.drawRect(border, mPaint);
    // draw more...
}

Edit

in the glorious chat the OP revealed that he uses the SurfaceView to draw a video on it. I suggested to change padding to margin and make the background of the parent view in MAGENTA.

The SurfaceView will be overdrawn completely by the video, therefor the above solution will not work with a video playback.

To sum it up: The OP wasted my time by not providing all necessary information. Thanks.

Upvotes: 1

Related Questions