1.在res/valuse/styles.xml
中添加如下代码
<!--是否显示标题窗口背景 透明窗口是否透明--><style name="NoTitleTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"><item name="android:windowNoTitle">true</item><item name="android:windowBackground">@color/transparentbg</item><item name="android:windowIsTranslucent">true</item></style>
2.然后在manifest.xml文件清单中在需要设置成透明背景的activity下引用该样式
在你的activity中添加如下代码:
<activity android:name=".MainActivity"android:theme="@style/NoTitleTranslucentTheme">