11

How can i make the background 50% transparent?
Let's say the background of an AbsoluteLayout so it's dark but you can still see through it?

2
  • AbsoluteLayout is deprecated.. you likely want a FrameLayout instead. Jun 25, 2010 at 0:04
  • mmm i cannot use anything else, I need to be able to add items to the screen at runtime, and set their x,y,width, and height. Is this possible with frame layouts?
    – aryaxt
    Jun 25, 2010 at 4:49

1 Answer 1

31

You could apply a transparent theme to the required activity. Create a new style in /res/values/style.xml

<resources>
<style name="Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
<item name ="android:windowBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>
</resources>

The value of transparent is

<color name="transparent">#00000000</color>

Now in AndroidManifest.xml declare the theme of the activity to the one you just created.

<activity android:name="MyActivity" android:theme="@style/Transparent"></activity>
4
  • Same question but on a standard Android Button (the default grey ones), can you make it 50% transparent ? I was just wondering ...
    – Hubert
    Jun 25, 2010 at 4:43
  • Answering this: if you want only 50% transparency, you would set the first 2 numbers to 50 instead of 00. So it would be #50000000 - the first 2 numbers in a color define the transparency level.
    – Booger
    Jul 1, 2012 at 15:43
  • 4
    @Booger , your statement about #50... resulting in 50% transparency is not correct. The color (and transparency) scale goes from 00 to FF in hexadecimal notation or from 0 to 255 in decimal. Thus, the correct html value for 50% transparency would be #7F000000.
    – Saran
    Oct 2, 2012 at 19:53
  • This works. My application was to disable touch but still allow a remote to press the underlying buttons of the app so I could not disable the buttons themselves. This is a very cleaver solution <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="match_parent" android:text="" android:background="#00000000" android:clickable="true"/> Dec 18, 2012 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.