Set Background color of Surface View

android, surfaceview

Solution

There's a workaround to do this.

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>

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.

Problem

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

Original source

Related problems