MainActivity.java文件。 ALPHA變量更改從0.0到1.0,看表面顏色red背景活動混色 package com.example.transparentsurfaceview;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class MainActivity extends Activity {
private GLSurfaceView mSurfaceView;
private static float ALPHA = 0.5f;
private static float RED = 1.0f;
private static float GREEN = 0.0f;
private static float BLUE = 0.0f;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSurfaceView = (GLSurfaceView)findViewById(R.id.mySurfaceView);
mSurfaceView.setEGLContextClientVersion(2);
mSurfaceView.setZOrderOnTop(true);
mSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
mSurfaceView.setRenderer(new GLSurfaceView.Renderer() {
public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
GLES20.glClearColor(RED, GREEN, BLUE, ALPHA);
}
public void onSurfaceChanged(GL10 gl10, int i, int i2) {}
public void onDrawFrame(GL10 gl10) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
});
}
}