android - 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();
解决方案
确保图像的背景是透明的,即当您在图像查看器中打开它时,它应该具有透明背景。
如果您想要透明背景,只需使用 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" />
推荐阅读
- powershell - 使用现有的 json 文件使用 Pester 和 TestDrive 进行测试
- java - 使用嵌套的 for 循环为二维数组赋值
- azure - 从 Azure 托管应用调用 Azure 自定义提供程序操作
- typescript - Typescript BigInt 添加问题:不能混合 BigInt 和其他类型,使用显式转换
- ruby - 如何修复 Homebrew 安装失败并显示“错误:无法安装 Homebrew Portable Ruby”
- python - 如何在同一个客户端中拥有套接字连接和 websocket 连接?
- powershell - 尝试读取新创建文件夹中的文件时,Powershell“权限被拒绝”
- rust - Rust:迭代 ASCII 字符串字符的最有效方法
- makefile - Makefile- 来自各种组件的文件 .c
- python - Python VLC 行为 - 播放后如何从 media_list 中删除以及我如何知道现在正在播放什么