Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Background color of Surface View

I want to set a background color to the surface view to my camera surface view.

I am using this for implementing the same. But this example is not complete. Can anyone please help me with some other useful link.

Thanks

like image 923
Gaurav Arora Avatar asked Mar 07 '13 16:03

Gaurav Arora


2 Answers

use surfaceview_obj.setBackgroundColor (int color) to set background color..

to set white color as background use this code

surfaceview_obj.setBackgroundColor(0Xffffffff);

check this

like image 114
Swarnendu Paul Avatar answered Sep 29 '22 03:09

Swarnendu Paul


There's a workaround to do this.

  1. add a parent viewgroup for the surfaceview, set the background color to this viewgroup instead of the surfaceview;

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_dark">
    
        <com.example.surfacetest.MySurface
            android:id="@+id/surface"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </FrameLayout>
    
  2. add the following for the SurfaceView instance;

    surfaceView.setZOrderOnTop(true);
    surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    

Now you get the background color you want and the surfaceview is tanslucent.

like image 43
wrkwrk Avatar answered Sep 29 '22 02:09

wrkwrk