【问题标题】:Make StackLayout transparent so the WebView behind can be seen使 StackLayout 透明,以便可以看到后面的 WebView
【发布时间】:2019-11-29 15:38:58
【问题描述】:

我使用的是 Visual Studio 2017,该项目是一个跨平台的 Xamarin Forms 移动应用,版本 4.0

我想在包含 webview 的 StackLayout 顶部添加一个包含非透明按钮的透明 StackLayout(页脚)。

我正在努力实现这一目标:

如你所见,底部StackLayout(Footer)的不透明度为0.9,仍然可以看到后面的WebView。

我试过这种方式:

<ContentPage.Resources>
        <ResourceDictionary>
            <Style x:Key="WebView" TargetType="{x:Type WebView}">
                <Setter Property="VerticalOptions" Value="Fill"></Setter>
                <Setter Property="HeightRequest" Value="1000"></Setter>
                <Setter Property="WidthRequest" Value="1000"></Setter>
            </Style>
            <Style x:Key="Footer" TargetType="{x:Type StackLayout}">
                <Setter Property="BackgroundColor" Value="{x:StaticResource BlackColor}"/>
                <Setter Property="VerticalOptions" Value="End"/>
                <Setter Property="Orientation" Value="Horizontal"/>
                <Setter Property="Opacity" Value="0.9"></Setter>
            </Style>
            <Style x:Key="AcceptButton" TargetType="{x:Type Button}">
                <Setter Property="BackgroundColor" Value="{x:StaticResource YellowColor}"/>
                <Setter Property="TextColor" Value="{x:StaticResource BlackColor}"/>
                <Setter Property="WidthRequest" Value="125" />
                <Setter Property="BorderRadius" Value="15" />
                <Setter Property="VerticalOptions" Value="CenterAndExpand" />
                <Setter Property="HorizontalOptions" Value="CenterAndExpand" />
            </Style>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <StackLayout>
            <StackLayout VerticalOptions="CenterAndExpand">
                <WebView Style="{StaticResource WebView}" Source="{Binding Url}"></WebView>
            </StackLayout>
            <StackLayout Style="{StaticResource Footer}">
                <Button Text="{x:Static resources:AppLocalization.Term_Accept}" Style="{StaticResource AcceptButton}"></Button>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

但是Footer全黑,看不到后面的WebView。 你们对如何处理这个有什么想法吗? 非常感谢!

【问题讨论】:

    标签: xamarin.forms webview


    【解决方案1】:

    你想覆盖项目,所以最好使用网格

     <ContentPage.Content>
            <Grid>
                <StackLayout VerticalOptions="CenterAndExpand">
                    <WebView Style="{StaticResource WebView}" Source="{Binding Url}"></WebView>
                </StackLayout>
                <StackLayout VerticalOptions="End" Style="{StaticResource Footer}">
                    <Button Text="{x:Static resources:AppLocalization.Term_Accept}" Style="{StaticResource AcceptButton}"></Button>
                </StackLayout>
            </Grid>
        </ContentPage.Content>
    

    【讨论】:

    • 这个可以,但是Accept按钮也是透明的,文字可以通过它看到,有没有办法让它不透明?谢谢!
    • 嗯,这与您的按钮样式有关(我不知道它是怎么回事)。不要忘记将 asnwer 标记为正确 :)
    • 按钮的样式在“AcceptButton”描述中,我尝试将不透明度设置为1,但它不起作用。你对此有什么建议吗?谢谢!
    • 哦,我明白了。那么解决方案是从 StackLayout 中删除 Opacity,而是使用 HEX Color 应用它,因为父布局中的不透明度也将应用于子布局。检查gist.github.com/lopspower/03fb1cc0ac9f32ef38f4
    • 太棒了!非常感谢!
    猜你喜欢
    • 2012-11-20
    • 2019-08-15
    • 1970-01-01
    • 2018-12-20
    • 2017-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多