首页 > 解决方案 > Xamarin Android 使背景透明

问题描述

我正在尝试在成功完成的操作上显示 png 图片,我希望使背景透明

<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>

活动中

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

标签: androidxamarin.android

解决方案


确保图像的背景是透明的,即当您在图像查看器中打开它时,它应该具有透明背景。

如果您想要透明背景,只需使用 White/Black 的十六进制代码并在其前添加 80:

因此,如果您在 XML 中执行此操作,它将类似于:

android:background="#80000000"

如果你是通过代码来做的,它会是这样的:

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

或者

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

更新:

这就是您的 XAML 的外观

<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" />


推荐阅读