Xamarin.Android - Form Transparent

47 Views Asked by At

In Xamarin Android, how to make a form completely transparent?

In my layout XML....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id ="@+id/LLBack"
android:background="@android:color/transparent"
>
</LinearLayout>

In my OnCreate...

LinearLayout ll = FindViewById<Android.Widget.LinearLayout>(Resource.Id.LLBack);
ll.SetBackgroundColor (Android.Graphics.Color.Transparent);`

but dont work :(

1

There are 1 best solutions below

1
Jessie Zhang -MSFT On

You can add a style to file styles.xml as follows:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
      <style name="AppTheme1" parent="android:Theme.Material.Light">

                        <item name="android:windowIsTranslucent">true</item>

                        <item name="android:windowBackground">@android:color/transparent</item>

                        <item name="android:windowContentOverlay">@null</item>

                        <item name="android:windowNoTitle">true</item>

                        <item name="android:windowIsFloating">true</item>

                        <item name="android:backgroundDimEnabled">false</item>

                        <!-- Customize your theme here. -->

                        <item name="android:windowIsFloating">true</item>

                  
      </style>
</resources>

And apply the style to your activity:

 [Activity(Label = "@string/app_name", Exported = true,Theme = "@style/AppTheme1" )]