android - Xamarin.Forms 中类似 colorAccent 的属性

标签 android xamarin.forms

在 Android AppCompact 库中,我们使用 colorAccent 属性为复选框和文本字段等 UI 控件设置主题。喜欢下面的图片。

<item name="colorAccent">#43ffd6</item>
<item name="colorAccent">#ff6f4d</item>

enter image description here enter image description here

如果我希望它在跨平台中生效,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/

相关文章:

c# - 将 XAML 中的按钮可见性绑定(bind)到 View 模型?

xaml - .Net Maui MVVM - 在页面/ View 打开时填充 CollectionView 的最佳方法是什么?

Release模式下的 Xamarin.Forms iOS 应用程序社区工具包 TouchEffect 命令未触发

android - 使用 Firebase 和 ChildEventListener 时如何在方向更改后保留 RecyclerView 的位置?

android - 将 aar 包含在 aar 中

android - '缺少类型或命名空间名称'

c# Xamarin 表单 : NavigationPage icon not showing

android - Nativescript 5.4.0 构建失败, "couldn' t 找不到 sbg-bindings.txt”

Android ActionBarCompat - 具有多个 fragment 的抽屉导航

c# - ListView 没有取消选择