[英]Background color of selecteditem in listview xamarin.forms
[英]Why background color stay white? (Xamarin.Forms Android)
我有一个 xamarin.forms 应用程序并尝试在 android 中发布它。 在我的模拟器中,背景的颜色是灰色的。 在 android 手机上,背景保持默认白色。 我错了什么?
<?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>
go 到 app.xaml 或 appshell.xaml 并更改背景颜色。
在这里工作。
在App.xaml
mainBg 和 mainBgBorder 中。 Android 手机处于 Lightmode。
<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>
我已经测试过了。 问题应该是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 的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.