尝试将您的背景颜色设置为稍微透明,即#55000000
或'#5000'。在res/values
文件夹中创建colors.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background">#55000000</color>
</resources>
然后在您的主题样式中使用该颜色:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourTheme" parent="android:@Theme.Translucent">
<item name="android:windowBackground">@color/background</item>
</style>
</resources>
关键在于将Theme.Translucent
作为您的样式的父级进行设置,我曾经尝试过使用Theme.Light
,但那并没有起作用。
我在我的应用程序里有同样的需求,我尝试了上面的解决方案,但不幸的是它对我不起作用。
在寻找相同问题的过程中,我发现了另一个解决方案,我想在这里分享一下,
我有一个名为Demo.java
的活动用于顶部显示,还有一个名为Test.java
的活动用于背景显示。所以我创建了一个样式并将其应用于Demo.java... 然后神奇地所有问题都得到了解决!
style.xml
<style name="Theme.D1NoTitleDim" parent="android:style/Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">@android:color/transparent</item>
</style>
并且在 Manifest.xml 中进行修改
<activity android:name="Demo"
android:theme="@style/Theme.D1NoTitleDim"></activity>
希望这也能帮到其他人。 愉快编码!!
在目标活动中(比如启动画面活动)必须进行以下更改:
public class SplashScreenActivity extends Activity {}
一定要将它扩展到活动中