设置表面视图的背景颜色

Gau*_*ora 10 android surfaceview

我想将表面视图的背景颜色设置为我的相机表面视图.

我正在使用来实现相同的功能.但这个例子并不完整.任何人都可以帮助我一些其他有用的链接.

谢谢

wrk*_*wrk 23

有一个解决方法来做到这一点.

  1. 为surfaceview添加父视图组,将背景颜色设置为此视图组而不是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>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 为SurfaceView实例添加以下内容;

    surfaceView.setZOrderOnTop(true);
    surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
    Run Code Online (Sandbox Code Playgroud)

现在你得到你想要的背景颜色,而surfaceview是tanslucent.

  • @wrkwrk:这很有效,但是这样做我无法覆盖SurfaceView的任何视图顶部.我们除了setXOrderOnTop(true)之外还有其他选择吗? (3认同)

Swa*_*aul 5

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

to set white color as background use this code

surfaceview_obj.setBackgroundColor(0Xffffffff);
Run Code Online (Sandbox Code Playgroud)

check this