Xamarin Forms自定义主题不起作用 [英] Xamarin Forms custom theme not working
问题描述
我有一个使用Xamarin Forms 2.0的Android应用.我制作了一个自定义主题来设置一些颜色.我创建了这些文件:
I have an Android app that uses Xamarin Forms 2.0. I made a custom theme to set some colors. I created these files:
Resources/values/styles.xml(AndroidResource)
Resources/values/styles.xml (AndroidResource)
<?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(AndroidResource)
Resources/values-v21/styles.xml (AndroidResource)
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="SmartbitLight" parent="SmartbitLight.Base">
</style>
</resources>
Resources/values/colors.xml(AndroidResource)
Resources/values/colors.xml (AndroidResource)
<?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,可以将这个主题连接到应用程序:
And then I have a MainActivity where I hook up this theme to the app:
[Activity(
Label = "Smartbit",
Icon = "@drawable/icon",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
Theme = "@style/SmartbitLight")]
public class MainActivity : FormsAppCompatActivity
但这无法正常工作:应用程序栏为白色而不是预期的蓝色,并且"android:windowBackground"也将我的Entry控件的文本和边框也变为白色.
This doesn't work correctly though: the app bar is white instead of the intended blue, and the 'android:windowBackground' turns the text and border of my Entry control white as well.
推荐答案
我设法使自定义主题与应用程序栏的所有颜色和所有内容一起使用.我创建了一个toolbar.axml文件,并将其注册到我的FormsAppCompatActivity中,如下所述: https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/.
I managed to get the custom theme working with all the colors for the appbar and everything. I created a toolbar.axml file and registered it in my FormsAppCompatActivity as described here: https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/.
这篇关于Xamarin Forms自定义主题不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!