Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Alpha level on view doesn't work

Tags:

android

I am trying to set the alpha level of a view. I am reading the documentation here:

http://developer.android.com/reference/android/widget/RelativeLayout.html

and it seems as if it should be possible even on android 2.1 which I am developing for (as I cant see it saying otherwise) but when I add it to my view

    <View
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="20sp"
    android:background="#ffffff"
   android:alpha="0.9"></View>

I get an error saying:

No resource identifier found for attribute 'alpha' in package 'android'

How do I set the alpha level of a view?

like image 915
Bex Avatar asked Aug 01 '11 14:08

Bex


2 Answers

you can set the alpha with the background properties like this way

android:background="#50ffffff"

here the first 50 value is set the alpha value

like image 142
Pratik Avatar answered Nov 18 '22 09:11

Pratik


On which android version are you running this?

setAlpha is only available on api level 11. You might try some other way to do this if you want to do this in previous versions. Probably using a semi-transparent background could do it.

like image 2
Pedro Loureiro Avatar answered Nov 18 '22 08:11

Pedro Loureiro