一、实现Activity透明或半透明的效果。(方法一:使用系统自带的方法)
在AndroidManifest.xml文件下进行配置,只要任意加一条到Activity中,就可以实现透明和半透明的效果,图如下。android:theme="@android:style/Theme.Translucent"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:theme="@android:style/Theme.Translucent"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
二、实现Activity透明或半透明的效果。(方法二:使用自定义的方法)
1在AndroidManifest.xml文件下进行配置
android:theme="@style/myTransparent"
2.在style文件下增加下面的代码。
<style name="myTransparent">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Toast</item>
</style>
3.在color文件下增加下面一行代码。
<color name="transparent">#0000</color>透明;
<color name="transparent">#9000</color>半透明;
三、实现SurfaceView透明的效果。
在SurfaceView的构造函数中,增加如下代码,就可以实现在SurfaceView上实现透明和半透明的效果。setZOrderOnTop(true);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
总结:通过以上的设置,就可以实现在activity上调用SurfaceView上实现透明显示的效果。