Xamarin Forms 自定义主题不工作

Xamarin Forms custom theme not working

我有一个使用 Xamarin Forms 2.0 的 Android 应用程序。我制作了一个自定义主题来设置一些颜色。我创建了这些文件:

Resources/values/styles.xml(Android资源)

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="SmartbitLight" parent="SmartbitLight.Base">

  </style>

  <style name="SmartbitLight.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/blueLight</item>
    <item name="colorPrimaryDark">@color/blueDark</item>
    <item name="colorAccent">@color/grey</item>
    <item name="android:windowBackground">@color/white</item>
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:statusBarColor">@color/blue</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
</resources>

Resources/values-v21/styles.xml(Android资源)

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="SmartbitLight" parent="SmartbitLight.Base">

  </style>
</resources>

Resources/values/colors.xml(Android资源)

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <color name="blueLight">#3cc1f1</color>
  <color name="blue">#33a4cd</color>
  <color name="blueDark">#33a4cd</color>
  <color name="grey">#7d7d7d</color>
  <color name="white">#ffffff</color>
</resources>

然后我有一个 MainActivity,我将这个主题连接到应用程序:

[Activity(
    Label = "Smartbit", 
    Icon = "@drawable/icon", 
    MainLauncher = true, 
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
    Theme = "@style/SmartbitLight")]
public class MainActivity : FormsAppCompatActivity

虽然这不能正常工作:应用栏是白色而不是预期的蓝色,并且 'android:windowBackground' 也将我的 Entry 控件的文本和边框变成白色。

尝试在清单中添加您的主题名称 (SmartbitLight),如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.test">
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="test" android:theme="@style/SmartbitLight"></application>
</manifest>

路径:your_app/Droid/Properties/AndroidManifest.xml

我设法让自定义主题与应用栏和所有内容的所有颜色一起使用。我创建了一个 toolbar.axml 文件并将其注册到我的 FormsAppCompatActivity 中,如下所述:https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/.