简体   繁体   中英

How to make activity transparent and work with other applications in android?

Hi 'stackoverflow' I've been trying to develop an android application which should remain on top of any other activity like a transparent one and also we should be able to touch and work with other activities, but our activity should stay on top of all other activities for ever until user explicitly kills our activity.

I made my activity transparent using the following code under my

'res/layout/styles.xml'

<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>

and in my

'manifest' I used

<activity
        android:name="com.example.transperentdroid.MainActivity"
        android:theme="@style/Theme.Transparent" >
        ........
</activity>

please help me to solve this riddle. Thanks in advance.

在您的活动布局文件中,将其放置在父布局项的属性中,

android:background="#000000"

res/values/styles.xml

<?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 value @color/transparent is the color value #00000000 which I put in res/values/color.xml file. You can also use @android:color/transparent in later Android versions)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM