Home  >  Q&A  >  body text

android - 如何创建透明activity?

我想在另外一个activity的顶部创建一个透明的activity,应该如何实现?

原问题:How to create Transparent Activity in Android?

PHPzPHPz2765 days ago862

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-17 11:27:59

    Answer: gnobal
    (Best answer)
    Add the following styles to your res/values/styles.xml file (create one if you don’t have one yet). This is 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>
    

    (The color value of @color/transparent I put in the res/values/color.xml file is #00000000. 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>
    

    Answer: yanchenko
    It can look like this:

    <activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    

    Answer: Deepak Swami
    You can use the following method to set it in the key list

    <activity android:name=".yourActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
    

    Then add a transparent background to the layout.


    Answer: androabhay
    In the key list, set the activity tag by adding the theme "@android:style/Theme.Translucent".


    Answer: jian
    Just set the activity background image to be transparent, or add a theme in the xml file,

    <activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    

    reply
    0
  • Cancelreply