如何在 Android 上创建透明的 Activity? [英] How do I create a transparent Activity on Android?

查看:27
本文介绍了如何在 Android 上创建透明的 Activity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个活动之上创建一个透明的活动.

I want to create a transparent Activity on top of another activity.

我怎样才能做到这一点?

How can I achieve this?

推荐答案

在您的 res/values/styles.xml 文件中添加以下样式(如果您没有,请创建它.) 这是一个完整的文件:

Add the following style in your res/values/styles.xml file (if you don’t have one, create it.) Here’s a complete file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>
</resources>

(值 @color/transparent 是我放在 res/values/color.xml 文件中的颜色值 #00000000.您也可以在以后的 Android 版本中使用 @android:color/transparent.)

(The value @color/transparent is the color value #00000000 which I put in the res/values/color.xml file. You can also use @android:color/transparent in later Android versions.)

然后将样式应用到您的活动中,例如:

Then apply the style to your activity, for example:

<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...
</activity>

这篇关于如何在 Android 上创建透明的 Activity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆