【发布时间】:2018-12-15 19:29:22
【问题描述】:
我正在使用以下 XML 来尝试更改 Xamarin 表单应用程序中开关的颜色。然而,什么都没有改变。
谁能给我任何关于我可能做错的建议:
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="android:actionBarSize">45dp</item>
<item name="colorPrimaryDark">#1976D2</item>
</style>
<style name="MyTheme.Switch" parent="Widget.AppCompat.CompoundButton.Switch">
<item name="colorControlActivated">#FF0000</item>
<item name="colorControlNormal">#FF0000</item>
<item name="colorControlHighlight">#FF0000</item>
<item name="colorSwitchThumbNormal">#FF0000</item>
<item name="colorAccent">#FF0000</item>
</style>
这是来自 MainActivity.cs 的剪辑
[Activity(Label = "Japanese", Icon = "@drawable/Icon120", Theme = "@style/MyTheme", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
由于这不起作用,我尝试了一些更改,但同样的问题是它不起作用:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="@android:style/Theme">
<item name="segmentedControlOptionStyle">@style/SegmentedControlOption</item>
<item name="switchStyle">@style/SwitchCompat</item>
</style>
</resources>
<style name="SwitchCompat" parent="@style/Widget.AppCompat.CompoundButton.Switch">
<item name="colorPrimary">#FFFF00</item>
<item name="colorPrimaryDark">#00FFFF</item>
<item name="colorAccent">#FF00FF</item>
</style>
【问题讨论】:
-
您是否尝试通过将样式传递给 MainActivity 来设置样式?就像这里解释的那样:forums.xamarin.com/discussion/70907/…
-
我更新了问题以显示 MainActivity
标签: xamarin xamarin.forms