在 Android AppCompact 库中,我们使用 colorAccent
属性为复选框和文本字段等 UI 控件设置主题。喜欢下面的图片。
<item name="colorAccent">#43ffd6</item>
<item name="colorAccent">#ff6f4d</item>
如果我希望它在跨平台中生效,Xamarin.Forms 是否有这样的属性。
最佳答案
如果您想要在 Xamarin.Forms 中对分组元素进行样式设置的主题方式,那么您可以使用样式 (Xamarin.Forms Styles),例如
var buttonStyle = new Style (typeof(Button)) {
Setters = {
new Setter {Property = Button.BackgroundColorProperty, Value = Color.Yellow},
new Setter {Property = Button.BorderRadiusProperty, Value = 0},
new Setter {Property = Button.HeightRequestProperty, Value = 42}
}
}
// apply directly to a single control
var mybutton = new Button {
Text = "Style Me",
Style = buttonStyle
};
您可以利用此功能提供可应用于多种类型的 UI 对象的主题样式。
如果样式不是你的“东西”(尽管老实说我看不出有什么理由不使用它们)那么你可以子类化有问题的 UI 对象并创建一个新的可绑定(bind)对象来负责设置相关属性.
祝你好运
关于android - Xamarin.Forms 中类似 colorAccent 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267900/