0

i have 3 activitie.i want to amake all of them transparent. i have created a styles.xml in values folder and attached the folllowing code

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

in my android manifest i have attached the following code

for all three activities

now my activities are getting transparent but whne i move from first activity to second activity to 2nd activity i see the 1st activity in the background

what should i do so that i see onlt the 2nd activity and 1st activity is not seen in the background

also can i make an activity semi transparent?

xandy
  • 27,357
  • 8
  • 59
  • 64
chinz
  • 31
  • 1
  • 7
  • You need to end the first activity explicitly if you don't wanna see it behind your transparent 2nd activity. – xandy Apr 06 '11 at 05:53
  • suppose i want to go back to previous activity then – chinz Apr 06 '11 at 05:55
  • consider i have a contacts application where 1st activity displays all contacts and second activity displays detail information of one contact . if i have ended activity 1 and went to 2nd activity and i again wish to go t back to 1st activity then wast should i do? – chinz Apr 06 '11 at 05:57
  • Seems not a good idea to remove the first activity. But this is the nature of Android, that activities will stack on each other if your choose they are transparent; better you reconsider the design of your UI. – xandy Apr 06 '11 at 06:00

3 Answers3

1

your problem is not in transparent. when you use startActivity(intent) for launching second or third activity you need add FLAG to intent. - Intent.FLAG_ACTIVITY_CLEAR_TOP

Roman Kazanovskyi
  • 3,370
  • 1
  • 21
  • 22
0

I would recommend to do this.

onPause(){
  finish();

}

do this to finish and release your previous activity. Or you can do this.

Intent.FLAG_ACTIVITY_CLEAR_TOP

Hope that helps.

androCoder-BD
  • 498
  • 7
  • 13
0

This contains the answer to your question:

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">@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)
Then apply the style to your activity, for example:

    <activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
    ...
    </activity>
Bob
  • 22,810
  • 38
  • 143
  • 225
Mark Mooibroek
  • 7,636
  • 3
  • 32
  • 53
  • @ Programmer XR:can i make an activity semi transparent – chinz Apr 06 '11 at 05:59
  • It seems he know how to apply the resources. – xandy Apr 06 '11 at 06:00
  • Semi transparent is possible, http://developer.android.com/reference/android/view/View.html#attr_android:background, color can accept #aarrggbb format. – xandy Apr 06 '11 at 06:01
  • @xandy:how do i make a window transparent and slightly blackish – chinz Apr 06 '11 at 06:28
  • can u let me know the color code for semi tansparent.i am unable to find it – chinz Apr 06 '11 at 06:30
  • May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb". ( the aa in #aarrggbb stands for alpha ) – Mark Mooibroek Apr 06 '11 at 06:32
  • do we have to set any opacity parameters – chinz Apr 06 '11 at 06:53
  • do we have to use any alpha blending.if so please let me know – chinz Apr 06 '11 at 06:57
  • semi trans white would be #50FFFFFF – Mark Mooibroek Apr 06 '11 at 06:57
  • whats for semi transparent grey – chinz Apr 06 '11 at 07:13
  • i developing an application on mobile where in the background video is playing and if any notification comes a dialog box will display.if i put it to transparent tor semi transparent it will show me the video below it which will make my dialog box look bad.i want to make my dialog box look like the semi transparent + light black or grey color – chinz Apr 06 '11 at 07:15
  • if u have seen ona android 2.2 home page icons appear of web menu and call on the right.they have a semi transparent grey color.i want like that color – chinz Apr 06 '11 at 07:18