【问题标题】:Xamarin Android Make background TransparentXamarin Android 使背景透明
【发布时间】:2019-03-29 08:14:30
【问题描述】:

我正在尝试在成功完成的操作上显示 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();

【问题讨论】:

    标签: android xamarin.android


    【解决方案1】:

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

    如果您想要透明背景,只需使用白色/黑色的十六进制代码并在其前添加 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" />
    

    【讨论】:

    • 是的,它是透明的,android:background="#80000000" 工作,非常感谢!
    • 当然,如果这对您有用,请将其标记为正确并点赞
    • 我试过 android:background="#80000000" ,看到这个链接它看起来像这样drive.google.com/file/d/1UDxeWDuJHPqAey6LJE5sNOGULS1oKXpz/…
    • 我很想接受这个答案,但是你看到那张照片了吗,也需要你的帮助,我希望我不是刻薄的,刚接触 Xamarin,所以很感动
    • 一点意思也不要担心
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2016-12-02
    • 2011-08-08
    • 2015-06-18
    • 1970-01-01
    相关资源
    最近更新 更多