Monodroid对话框透明背景
Monodroid Dialog transparent background
我正在尝试在 Xamarin android 中将我的对话框背景设置为透明,但我无法正确实现。
http://i.stack.imgur.com/VFYZs.jpg
即使我将背景设置为透明,对话框顶部仍然有一条蓝线。我怎样才能让我的背景完全透明。谢谢。
主要Activity;
[Activity(Label = "LoadingExample2", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private Dialog builder;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
builder = new Dialog(this);
var view = LayoutInflater.Inflate(Resource.Layout.Loading,null);
builder.SetContentView(view);
builder.Window.SetBackgroundDrawableResource(global::Android.Resource.Color.Transparent);
button.Click += delegate
{
builder.Show();
};
}
}
Loading.axml;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#00ffffff"
android:id="@+id/relativeLayout2">
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout1"
android:layout_centerInParent="true"
android:padding="5dp"
android:background="@android:color/background_light">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar1"
android:layout_centerHorizontal="true" />
<TextView
android:text="Loading"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:textColor="@android:color/black"
android:layout_below="@id/progressBar1"
android:textSize="15sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
一个简单的方法是隐藏栏本身:
int divierId = builder.Window.Context.Resources.GetIdentifier("android:id/titleDivider", null, null);
builder.Window.FindViewById(divierId)
.SetBackgroundColor(Resources.GetColor(global::Android.Resource.Color.Transparent));
我正在尝试在 Xamarin android 中将我的对话框背景设置为透明,但我无法正确实现。
http://i.stack.imgur.com/VFYZs.jpg
即使我将背景设置为透明,对话框顶部仍然有一条蓝线。我怎样才能让我的背景完全透明。谢谢。
主要Activity;
[Activity(Label = "LoadingExample2", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private Dialog builder;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
builder = new Dialog(this);
var view = LayoutInflater.Inflate(Resource.Layout.Loading,null);
builder.SetContentView(view);
builder.Window.SetBackgroundDrawableResource(global::Android.Resource.Color.Transparent);
button.Click += delegate
{
builder.Show();
};
}
}
Loading.axml;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#00ffffff"
android:id="@+id/relativeLayout2">
<RelativeLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout1"
android:layout_centerInParent="true"
android:padding="5dp"
android:background="@android:color/background_light">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar1"
android:layout_centerHorizontal="true" />
<TextView
android:text="Loading"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:textColor="@android:color/black"
android:layout_below="@id/progressBar1"
android:textSize="15sp"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
一个简单的方法是隐藏栏本身:
int divierId = builder.Window.Context.Resources.GetIdentifier("android:id/titleDivider", null, null);
builder.Window.FindViewById(divierId)
.SetBackgroundColor(Resources.GetColor(global::Android.Resource.Color.Transparent));