- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想更改位于 TabbedPage 的 ToolbarItem 中的几个图标,我查看了文档 here ,我要么没有捕获要点,要么我希望实现的目标是不可行的?
我目前正在使用 FontAwesomeIcons 在我的应用程序中填充图标,从静态的角度来看它们效果很好。但在某些情况下,我可能希望更改图标或其颜色或图标包(例如从浅色到纯色)。
App.xaml - 我用它来引用我的 .otf 文件
<Application.Resources>
<OnPlatform x:Key="FontAwesomeProLight" x:TypeArguments="x:String">
<On Platform="iOS" Value="FontAwesome5Pro-Light" />
</OnPlatform>
<OnPlatform x:Key="FontAwesomeProSolid" x:TypeArguments="x:String">
<On Platform="iOS" Value="FontAwesome5Pro-Solid" />
</OnPlatform>
</Application.Resources>
ExamplePage.xaml - 这将是我当前(非动态)显示我的图标的页面
<TabbedPage.ToolbarItems>
<ToolbarItem Clicked="OnFilterOrders">
<ToolbarItem.IconImageSource>
<FontImageSource FontFamily="{StaticResource FontAwesomeProLight}" Glyph="{x:Static fonts:FontAwesomeIcons.Filter}" />
</ToolbarItem.IconImageSource>
</ToolbarItem>
</TabbedPage.ToolbarItems>
所以此时的代码可以完美地显示静态图标,下面是我失败的尝试 - 但没有抛出错误,我只是得到一个?相反
ExamplePage.xaml
<TabbedPage.ToolbarItems>
<ToolbarItem Clicked="OnFilterOrders">
<ToolbarItem.IconImageSource>
<FontImageSource FontFamily="{DynamicResource FontAwesomeIconPack}" Glyph="{x:Static fonts:FontAwesomeIcons.Filter}" />
</ToolbarItem.IconImageSource>
</ToolbarItem>
</TabbedPage.ToolbarItems>
使用该页面的代码隐藏,我在构造函数中也有以下内容。
Resources["FontAwesomeIconPack"] = App.Current.Resources["FontAwesomeProLight"];
我假设 Resources["FontAwesomeIconPack"] 链接到页面资源字典,App.Current.Resources["FontAwesomeProLight"] 链接到 app.xaml 页面是否正确?
我希望在这个例子中我能显示我现有的图标,但它没有。我的期望是与以前(在我更改包装之前)相同的图标,但我只是得到一个?)。
最佳答案
如果你想在运行时改变标签图标的样式(比如图标,字体大小)。你应该使用Custom Renderer。
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using xxx;
using xxx.iOS;
[assembly:ExportRenderer(typeof(TabbedPage),typeof(MyTabbedPageRenderer))]
namespace xxx.iOS
{
public class MyTabbedPageRenderer:TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
}
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
MessagingCenter.Subscribe<Object, int>(this, "ChangeStyle", (args, position) => {
UpdateItem(TabBar.Items[position], "xxx.png","xxx2.png");
});
}
void UpdateItem(UITabBarItem item, string icon,string selectIcon)
{
if (item == null)
{
return;
}
// set default icon
if (item?.Image?.AccessibilityIdentifier == icon)
return;
item.Image = UIImage.FromBundle(icon);
item.Image.AccessibilityIdentifier = icon;
//set select icon
if (item?.SelectedImage?.AccessibilityIdentifier == selectIcon)
return;
item.SelectedImage = UIImage.FromBundle(selectIcon);
item.SelectedImage.AccessibilityIdentifier = selectIcon;
//set font
item.SetTitleTextAttributes(new UITextAttributes() { Font=UIFont.SystemFontOfSize(10,UIFontWeight.Light)},UIControlState.Normal);
item.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.SystemFontOfSize(10, UIFontWeight.Light) }, UIControlState.Selected);
}
}
}
你可以查看这个blog ,它通过使用 Custom Renderer 在 Android 中提供解决方案。
使用 MessagingCenter 在需要时发送消息(例如单击按钮)
MessagingCenter.Send<Object, int>(this, "ChangeStyle", 0);
关于c# - 是否可以动态更改 ToolbarItem 的图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58273502/
有一种方法可以在 Xamarin.Forms 中设置 ToolBarItem 中的图标的尺寸吗? 看起来改变图标的大小只会降低质量,留下相同大小的图标。 是否需要自定义渲染器?我应该怎么做? 最佳
我想更改位于 TabbedPage 的 ToolbarItem 中的几个图标,我查看了文档 here ,我要么没有捕获要点,要么我希望实现的目标是不可行的? 我目前正在使用 FontAwesomeIc
NSToolbar items 属性在 windowDidLoad 上仍然是空的 //WindowController override func windowDidLoad() { supe
我想要的按钮与 iOS 中的提醒应用程序完全一样在代码注释工作下方,我还尝试使用标签和系统图像名称。 .toolbar { ToolbarItem(placem
我有一个带有四 (4) 个 TabBarItems 的 TabBarController ...我如何处理每个 TabBarItem 以便我可以捕获被点击的事件? 最佳答案 将委托(delegate)
通常,出于可访问性的原因,我喜欢坚持使用默认颜色选项,但我有一个特定的用例,我无法更改单个 .toolbar ToolbarItem 颜色。 我可以使用代码段顶部注释掉的代码覆盖所有 ToolbarI
我正在 Xamarin Forms 中创建 Android 应用程序。我正在尝试使用 this 中的一些示例添加 ToolbarItem 图标论坛使用 XAML,如下所示: 我的Create.png
在学习本教程时 https://xamarinhelp.com/xamarin-forms-toolbar/ 我遇到了一个小问题,项目在 Android 上显示良好,但在 UWP 工具栏上关闭导致项目
我将 Xamarin 的 ToolbarItems 类与 XAML 一起使用: 有没有办法改变所有工具栏项的背景颜色和文本颜色? 最佳答案 创建导航页面时,您可以更改 ToolbarIt
我有一个带有 FreshMvvm 的 Xamarin.Forms 应用程序,我正在尝试使用辅助 ToolbarItems。这是我的 PageModel 代码的一部分: public overrid
我正在使用 Xamarin.UITest 编写一些自动化程序。目标应用在其标记中包含此内容: 到目前为止,我有 3 种方法: 使用 .Class 和索引成功找到元素 systemMenu
我的页面中有以下内容: 该命令启动一个异步任务。只要异步任务仍在运行,我就会尝试通过将其绑定(bind)到 bool 属性来禁用该控件,如下所示: 我的问题是 Toolba
我的 xamarin android 项目在资源下没有 Drawawble 文件夹,我有我正在尝试为共享项目中的工具栏项设置图标。如果我将图像设置为嵌入式资源,我应该能够从共享项目访问它,我错了吗
我不知道这是一个错误还是我在这里做错了什么。我在导航栏上添加了一个新按钮,它将呈现一个新 View 。 struct MyView: View { @ObservedObject var vi
我正在寻找一种向我的 ToolbarItem 添加菜单的方法。现在它只是可点击的文本,这是我正在尝试创建的示例, 这是我到目前为止所拥有的: 最佳答案 您应该能够将 To
我正在尝试找到一种方法将关闭的 ToolBarItem 放在工具栏的左侧。为了更明确,这里有一些屏幕截图: 对于安卓: 对于 iOS: 问题不在于显示图标而不是文本,我正在使用 Iconize。问题在
我正在尝试使用带有过滤器图标的 MVVM 构建工具栏。当您单击它时,您会导航到设置过滤器的位置,然后导航回来。如果筛选器对所选项目处于 Activity 状态,我希望工具栏图标现在成为不同的图像。 但
我正在尝试将 UIButtonTypeDetailDisclosure 添加到 View 的底部栏。 应用程序构建成功,但在运行时出现以下错误: *** Terminating app due to
当 ToolbarItem 的顺序设置为 Secondary 用于 IOS,以使其看起来像 Android 一样。 这里有一些图片可以更好地解释我在寻找什么: 它在 Android 上的工作原理: 代
我希望使用 Xamarin Forms 共享项目显示通知,如下图链接所示。有没有办法在工具栏项目的图标上添加文本/数字? Follow this link to view example since
我是一名优秀的程序员,十分优秀!