Android 透明主题

转至:https://blog.csdn.net/zhangwenchaochao/article/details/78654128

Activity采用透明主题有两种方式:

重要的内容说三遍:
采用透明主题的Activity一定要继承Activity,不然会崩溃。
采用透明主题的Activity一定要继承Activity,不然会崩溃。
采用透明主题的Activity一定要继承Activity,不然会崩溃。

方法一
在你的AndroidManifest里的Activity标签里配置透明主题:

android:theme=”@android:style/Theme.Translucent”
android:theme=”@android:style/Theme.Translucent.NoTitleBar”
android:theme=”@android:style/Theme.Translucent.NoTitleBar.Fullscreen”

第一种保留标题和状态栏,其他为透明色
第二种保留状态栏,其他为透明色
第三种全屏透明

以上三种选一种即可。

例子
<activity android:name=".touming1Activity" android:theme="@android:style/Theme.Translucent" />
1
2
这是刚刚进来的界面,没有透明

 

 

采用第一种透明模式:

 

 

方法二
自己定义一种样式,然后在AndroidManifest的Activity标签中采用。

例子
在value的styles中定义如下style

<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
1
2
3
4
5
别忘了在colors里面定义透明色调

<color name="transparent">#00000000</color>
1
然后在AndroidManifest的Activity标签中采用:

<activity android:name=".touming2Activity" android:theme="@style/Transparent" />
---------------------
作者:时光匠
来源:CSDN
原文:https://blog.csdn.net/zhangwenchaochao/article/details/78654128
版权声明:本文为博主原创文章,转载请附上博文链接!

posted @ 2019-07-04 09:34  jdhdevelop  阅读(2717)  评论(0编辑  收藏  举报