为什么背景颜色保持白色?(Xamarin.表单Android)

mzsu5hc0  于 2022-12-07  发布在  Android
关注(0)|答案(3)|浏览(189)

我有一个xamarin.forms应用程序,并尝试在android中发布它。在我的模拟器中,背景颜色是灰色的。在android mobile中,背景保持默认的白色。我错了什么?

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=http://xamarin.com/schemas/2014/forms
             xmlns:x=http://schemas.microsoft.com/winfx/2009/xaml
             xmlns:local="clr-namespace:MyApp"
             x:Class="MyApp.MainPage"
             BackgroundColor="#202020">
    <StackLayout Style="{StaticResource mainBg}">
        <ScrollView BackgroundColor="#202020">
            <StackLayout  Style="{StaticResource mainBg}">
                <Frame HasShadow="True" Style="{StaticResource mainBgBorder}">
                    <StackLayout VerticalOptions="StartAndExpand">
                        <Image x:Name="imMyPicLogo" Source="MyPic.png" HeightRequest="50" HorizontalOptions="End"></Image>
                    </StackLayout>
                </Frame>
          </StackLayout>
        </ScrollView>
    </StackLayout>
</ContentPage>
iugsix8n

iugsix8n1#

转到app.xaml或appshell.xaml并更改背景颜色。

u0sqgete

u0sqgete2#

在这里工作。
App.xaml mainBg和mainBgBorder中,Android手机处于光照模式。

<Application.Resources>
    <Style TargetType="StackLayout" x:Key="mainBg">
        <Setter Property="BackgroundColor" Value="#202020" />
    </Style>

    <Style TargetType="Frame" x:Key="mainBgBorder" >
        <Setter Property="BackgroundColor" Value="Gray" />
    </Style>
</Application.Resources>

那么ContentPage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="BackgroundSO.MainPage"
         BackgroundColor="#202020">
<StackLayout Style="{StaticResource mainBg}">
    <ScrollView BackgroundColor="#202020">
        <StackLayout  Style="{StaticResource mainBg}">
            <Frame HasShadow="True" Style="{StaticResource mainBgBorder}">
                <StackLayout VerticalOptions="StartAndExpand">
                    <Image x:Name="imMyPicLogo" Source="schip.png" HeightRequest="50" HorizontalOptions="End"></Image>
                </StackLayout>
            </Frame>
        </StackLayout>
    </ScrollView>
</StackLayout>

piwo6bdm

piwo6bdm3#

我已经测试过了,问题应该是stacklayout的style属性设置,你可以试着这样修改一下:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=http://xamarin.com/schemas/2014/forms
         xmlns:x=http://schemas.microsoft.com/winfx/2009/xaml
         xmlns:local="clr-namespace:MyApp"
         x:Class="MyApp.MainPage"
         BackgroundColor="#202020">
<StackLayout>
    <ScrollView BackgroundColor="#202020">
        <StackLayout  Style="{StaticResource mainBg}">
            <Frame HasShadow="True" Style="{StaticResource mainBgBorder}">
                <StackLayout VerticalOptions="StartAndExpand">
                    <Image x:Name="imMyPicLogo" Source="MyPic.png" 
HeightRequest="50" HorizontalOptions="End"></Image>
                </StackLayout>
            </Frame>
      </StackLayout>
    </ScrollView>
</StackLayout>
</ContentPage>

顺便说一下,如果可以的话,您可以提供更多关于mainBgBorder的信息。

相关问题