Android Guides | Samples

Android.Graphics.Drawables.ShapeDrawable.Opacity Property

Return the opacity/transparency of this Drawable.


[get: Android.Runtime.Register("getOpacity", "()I", "GetGetOpacityHandler")]
public override Int32 Opacity { get; }


Return the opacity/transparency of this Drawable. The returned value is one of the abstract format constants in PixelFormat: Format.Unknown, Format.Translucent, Format.Transparent, or Format.Opaque.

An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.

Generally a Drawable should be as conservative as possible with the value it returns. For example, if it contains multiple child drawables and only shows one of them at a time, if only one of the children is TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be returned. You can use the method Drawable.ResolveOpacity(Int32,Int32) to perform a standard reduction of two opacities to the appropriate single output.

Note that the returned value does not necessarily take into account a custom alpha or color filter that has been applied by the client through the Drawable.SetAlpha(Int32) or Drawable.SetColorFilter(ColorFilter) methods. Some subclasses, such as BitmapDrawable, ColorDrawable, and GradientDrawable, do account for the value of Drawable.SetAlpha(Int32), but the general behavior is dependent upon the implementation of the subclass.

[Android Documentation]


Namespace: Android.Graphics.Drawables
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions:
Since: Added in API level 1