我们不生产代码,我们知识代码的搬运工,如有侵权,本人将第一时间删除
邮箱:zhf6751134@163.com
QQ交流群:336237986
方法一:
通过Theme.Translucent
<activity
android:name=".activity.PublishTalentActivity"
android:theme="@android:style/Theme.Translucent " />
以下三种 任意选一种
@android:style/Theme.Translucent
@android:style/Theme.Translucent.NoTitleBar
@android:style/Theme.Translucent.NoTitleBar.Fullscreen
方法二:
自定义style,就像自定义Dialog的style一样,
在res-values-color.xml中添加透明颜色值:
?xml version=”1.0” encoding=”UTF-8”?>
?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="transparent">#0000</color>
</resources>
- 在res-values-styles.xml中添加如下:
<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.Translucent</item>
</style>
- 在Manifest中中需要透明的Activity内设置theme为我们自定义的即可
android:theme="@style/myTransparent"
注意Android Studio的坑
今天在使用这两种方法设置时,都出现了闪退,
解决办法
- 经过各种测试发现 是我将要设置的Activity 继承的AppCompatActivity,只要继承 Activity 一切就OK 了
- 让自定义样式 继承兼容主题
<style name="myTransparent" parent="Theme.AppCompat.Light.NoActionBar">
<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.Translucent</item>
</style>
(欢迎加入Android交流QQ群: 336237986)