如何在便携式跨平台 xamarin 表单中将表单背景设置为透明度?

Kir*_*are 10 android xamarin.ios ios

我正在使用便携式 xamarin 跨平台。我有两个项目 android 和 IOS。

我必须把表格做成透明的形式。我已经为相同的代码编写了代码,这段代码在 android 中完美运行,但在 IOS 中却没有

下面是我的代码:

  <ContentPage BackgroundColor="#00000000">

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="180"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
                <RowDefinition Height="200"></RowDefinition>
            </Grid.RowDefinitions>

            <StackLayout Grid.Row="0" VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#80000000" HeightRequest="175" >

            </StackLayout>

            <BoxView HeightRequest="200" Grid.Row="1"></BoxView>

            <StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand"  BackgroundColor="#80000000" HeightRequest="160"  Grid.Row="2" >
                <Label Text="05:00" FontSize="60" FontAttributes="Bold" TextColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" ></Label>
            </StackLayout>
        </Grid>  

   </ContentPage>
Run Code Online (Sandbox Code Playgroud)

下面是安卓截图:

在此处输入图片说明

以下是IOS截图:

在此处输入图片说明

请建议我如何在两个平台上都有透明度表格

提前致谢

小智 12

更简单的解决方案是仅更改 alpha 通道的十六进制值。

FBC1BC 是纯色,但#00FBC1BC 是透明的,因为 00 将颜色的 alpha 设置为 0 或透明。

所以就这样做#FBC1BC > #50FBC1BC

您将获得一个透明的背景颜色,其 alpha 由前两个值定义!


Him*_*edi 8

只需在 stacklayout 中包含 opacity 属性:

<StackLayout VerticalOptions="End" HorizontalOptions="FillAndExpand"  BackgroundColor="#80000000" Opacity="0.5" HeightRequest="160"  Grid.Row="2" >
  <Label Text="05:00" FontSize="60" FontAttributes="Bold" TextColor="White" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" ></Label>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)

  • 通过使用 Opacity,stacklayout 变得透明。我不想透明堆栈布局。我需要将内容页面/表单背景颜色设置为透明。 (2认同)