Nancy Kanwar
Nancy Kanwar

Reputation: 157

Xamarin Android Make background Transparent

I'm trying to Display a png Picture on an Operation which is successfully Completed, I wish to make the Background Transparent

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@android:color/transparent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:src="@drawable/successful"
        android:layout_width="250dp"
        android:layout_gravity="center"
        android:layout_height="140dp"
        android:id="@+id/imageView1" />

</LinearLayout>

In Activity

Dialog alert;
alert = new Dialog(this);
alert.SetContentView(Resource.Layout.SuccessfulPopup);
alert.Show();

Upvotes: 2

Views: 1967

Answers (1)

FreakyAli
FreakyAli

Reputation: 16562

Make sure your image's background is transparent i.e. when you open it in an image viewer it should have a transparent background.

If you want a transparent background just use the hex code of White/Black and add 80 before it:

So if you are doing this in In XML it would be something like:

android:background="#80000000"

And if you are doing it through the code it would be something like:

imageView.SetBackgroundColor(Color.Parse("#80000000")); 

or

imageView.SetBackgroundColor(Android.Graphics.Color.Transparent);

Update:

This is how your XAML should look

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:src="@drawable/successful"
    android:layout_width="250dp"
    android:layout_gravity="center"
    android:background="@android:color/transparent"
    android:layout_height="140dp"
    android:id="@+id/imageView1" />

Upvotes: 1

Related Questions