android activity设置透明或者半透明背景

版权声明:本文为博主原创文章,未经博主允许不得转载,请尊重知识产权 https://blog.csdn.net/yishichangan1/article/details/78143777

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">

猜你喜欢

转载自blog.csdn.net/yishichangan1/article/details/78143777