I'm not able to set the background transparent on API 19, instead I get a white background. The background is only transparent on API 21 and above.
I have an activity that calls a custom dialog fragment. The parent layout of dialog fragment has background="@android:color/transparent"
.
What am I doing wrong? Am I missing something. Any tips of hint would be really helpful.
Solutions that I have tried:
Changing primary color to transparent on MyActivityTheme
Parent layout background="@null"
Dialog with transparent background in Android
How to make any view background transparent?
MyDialogFragment
public class MyDialogFragment : DialogFragment
{
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle(DialogFragmentStyle.NoTitle, Resource.Style.MyDialogTheme);
}
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
var builder = new AlertDialog.Builder(Activity);
var inflater = Activity.LayoutInflater;
var dialogView = inflater.Inflate(Resource.Layout.MyDialogLayout, null);
if (dialogView != null)
{
builder.SetView(dialogView);
}
var dialog = builder.Create();
dialog.Window.RequestFeature(WindowFeatures.NoTitle);
dialog.Window.SetBackgroundDrawable(new ColorDrawable(Android.Graphics.Color.Transparent));
return dialog;
}
}
MyDialogLayout
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content">
<!-- Child layouts -->
</LinearLayout>
Styles.xml
<style name="MyActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/Red</item>
<item name="colorAccent">@color/White</item>
<item name="colorControlNormal">@color/White</item>
<item name="colorControlActivated">@color/White</item>
<item name="android:textColorHint">@color/White</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
<style name="MyDialogTheme" parent="android:Theme.Holo.Light.Dialog.NoActionBar">
<item name="colorPrimary">@android:color/transparent</item>
<item name="colorAccent">@color/Red</item>
<item name="colorControlNormal">@color/Red</item>
<item name="colorControlActivated">@color/Red</item>
<item name="colorControlHighlight">@color/Red</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textColorPrimary">@color/Red</item>
</style>