xaml - Android 上的全局样式问题,iOS 工作正常(Xamarin)
问题描述
我在 Xamarin 应用程序中遇到了一些奇怪的行为。在共享项目中,我将所有基于控件的样式分隔在单个 xaml 文件中。
所有样式都组合在DefaultTheme.xaml
文件中。
然后, DefaultTheme.xaml 将被LightTheme.xaml
and使用DarkTheme.xaml
。
我的风格就是这样管理的。然后,根据“Darkomde on/off”,我可以在 iOS 和 Android 项目中加载LightTheme.xaml
或。DarkTheme.xaml
在 Android 上,我在 MainActivity.cs 中设置了这样的主题(我也在使用 SplashActivity.cs,应该已经设置了吗?)
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
SetAppTheme();
}
void SetAppTheme()
{
if (Resources.Configuration.UiMode.HasFlag(UiMode.NightYes))
SetTheme(RemoteControlRepetierServer.Theme.Dark);
else
SetTheme(RemoteControlRepetierServer.Theme.Light);
}
public void SetTheme(Theme theme)
{
switch (theme)
{
case RemoteControlRepetierServer.Theme.Light:
// Night mode is not active, we're using the light theme
if (App.AppTheme == "light")
return;
App.Current.Resources = new LightTheme();
App.AppTheme = "light";
break;
case RemoteControlRepetierServer.Theme.Dark:
// Night mode is active, we're using dark theme
if (App.AppTheme == "dark")
return;
//Add a Check for App Theme since this is called even when not changed really
App.Current.Resources = new DarkTheme();
App.AppTheme = "dark";
break;
}
App.CurrentAppTheme = theme;
}
到目前为止,一切都很好。现在,如果我启动我的 Android 应用程序,似乎并没有加载所有样式。例如Gauge
. 虽然第一个选项卡上的仪表看起来应该如此,但第二个选项卡上的仪表却没有。
两者都使用相同的 XAML 进行样式设置。
<gauge:Scale.Pointers>
<gauge:NeedlePointer Value="{Binding SelectedExtruder.TempRead}" Color="{DynamicResource Gray-Black}"
KnobColor="{DynamicResource Gray-Black}" KnobStrokeColor="{DynamicResource Gray-Black}"/>
<gauge:RangePointer Value="{Binding SelectedExtruder.TempRead}" Color="{DynamicResource PrimaryColor}"
RangeCap="Both"
/>
<gauge:MarkerPointer Value="{Binding SetExtruderTemp}" Color="{DynamicResource Red}"/>
</gauge:Scale.Pointers>
也没有在第二个选项卡上设置控件的Style
。NumericUpDown
这只发生在 Android 上,iOS 的所有选项卡看起来都很好。我不确定是什么导致了这个问题。任何帮助表示赞赏。如果您需要更多信息或代码片段,请告诉我。
解决方案
刚刚发现使用SyncfusionTheme
导致这种行为。一旦我将它从 中删除MergedDictionaries
,它就起作用了。
推荐阅读
- git - git存储库未在intellij中加载
- python - 如何分组和绘制聚合数据?
- machine-learning - 深度神经网络模型在一个 epoch 后停止学习
- batch-file - 无明显原因关闭批处理文件
- python - 如何在tensorflow中重用操作?
- python - 具有实际环境而不是 python 类环境的 TensorFlow 代理
- apache-kafka - 删除 Kafka/log 旧文件是否安全?
- python - 如何让我的函数在以下代码中在 tkinter 中配置正确的标签?
- javascript - 如何自动化应用程序脚本中的特定范围
- java - 错误:不兼容的类型:从 double 到 float 的可能有损转换