问题描述
我正在创建 Xamarin.Forms
应用程序(Android 和 iOS),但在使用 DatePicker
、Switch
和其他控件时遇到图形问题。
我尝试在多个 Android 设备上构建新的示例应用程序(Visual Studio 随附),但问题仍然存在。 不过我在 Andorid 模拟器上没有遇到这个问题。
任何帮助表示赞赏。谢谢
解决方法
这是因为设备的主题。 (暗光)。您可以通过将这些添加到 style.xml
来覆盖颜色<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.DayNight">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from https://aka.ms/material-colors -->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/colorAccent</item>
<!-- You can also set colorControlNormal,colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:statusBarColor">#000000</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>