Background transparency problem caused by translucent app
I encountered a problem a few days ago: the app is half-screen. In order not to make the other part of the background black, the following style attributes are set
<item name="android:windowIsTranslucent">true</item>
At the same time, the app integrates unity, and unity uses a translucent background image.
After running, the unity part of the app shows through the desktop.
Solution:
First, if unity wants to have a hierarchical relationship, you need to set z
// surfaceView 透明化
for (i in 0 until unityPlayer.childCount) {
if (unityPlayer.getChildAt(i) is SurfaceView) {
val tmp = unityPlayer.getChildAt(i) as SurfaceView
tmp.holder.setFormat(PixelFormat.OPAQUE)
tmp.setZOrderOnTop(true)
tmp.setZOrderMediaOverlay(true)
}
}
In addition, if you want to be opaque, you need to set the format
You can see the source code of unity Player