1

Say I have a menu sliding out in android and I want to darken whatever was behind it.

I tied making a full screen layout and use a countdown timer to make its background gradually go from transparent to 50% black, but it gets slow as hell.

Are there any other options to make a gradual transition? Other then making it in a snap?

Thanks!

Animesh
  • 4,926
  • 14
  • 68
  • 110
Roger Travis
  • 8,402
  • 18
  • 67
  • 94
  • Did you have a look at Android's [animations](http://developer.android.com/guide/topics/resources/animation-resource.html#Tween)? – JimmyB Jan 25 '12 at 18:29
  • Yes, I tried making the background black, and setting alpha to 0 and then gradually raising it with a count down times, but it also seems a bit too slow... – Roger Travis Jan 25 '12 at 19:02
  • When talking about "count down timer", I assume you did *not* define your animation in XML, define and set an interpolator, and then just let the OS handle timing and display? - Maybe have a look at [this](http://stackoverflow.com/questions/6796139/fade-in-fade-out-android-animation-in-java) question/answer which seems to achieve the effect you desire. – JimmyB Jan 25 '12 at 19:10
  • THANKS! Made it with animations, and looks much better! :=) – Roger Travis Jan 25 '12 at 20:48

1 Answers1

0

Why don't you use a theme? Under res/values, make a styles.xml file. In that, define

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

Then in your manifest:

<activity android:name="com.example.FooActivity" android:theme="@style/Theme.Translucent"></activity>
Dhruv Gairola
  • 9,102
  • 5
  • 39
  • 43