是否可以根据字体大小缩放标签、按钮和框架?我遇到了 accessibility
问题,其中 iOS
有几行可以禁用所有辅助功能缩放,而在谷歌搜索后 android 似乎根本没有它。我有许多内部有文本的组件和具有自定义字体的按钮,这些按钮具有自定义字体的 arrows
pause
和 play
图标。我需要根据辅助功能中的字体大小是否已更改来缩放整个按钮。
仅适用于 iOS:Accessibility Scaling for Named Font Sizes on iOS ,找不到有关 android 的任何内容。
另一篇文章:Getting Android/iOS Accessibility font sizes ,第一个答案有这行适用于 android Android.Content.Res.Resources.System.Configuration.FontScale
的代码,但我似乎无法访问 Android.Content
任何我尝试使用它的地方。
提前非常感谢。
编辑: Temp Fix 。仍然想知道是否可以使用字体大小进行组件缩放。
引用:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BugTestMediaElement.Page3">
<Shell.TitleView>
<StackLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
BackgroundColor="Red">
<Frame BackgroundColor="White"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand">
<Label Text="Test"
FontSize="{StaticResource ToolbarIconFontSize}"
TextColor="Black" />
</Frame>
</StackLayout>
</Shell.TitleView>
</ContentPage>
最佳答案
我使用以下方法。在 App.xaml
文件(应用程序范围声明)中,我做出以下声明:
<Application.Resources>
<ResourceDictionary>
<OnPlatform x:Key="ToolbarIconFontSize" x:TypeArguments="x:Double" Android="48" iOS="64" />
</ResourceDictionary>
</Application.Resources>
然后在页面上(我使用 FontAwesome 的图标),我做出以下声明:
<Shell.TitleView>
<Grid Style="{StaticResource GridTitle}" RowDefinitions="*" ColumnDefinitions="*, 0.20*, 0.20*">
<!-- other declarations are skipped -->
<ImageButton Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" Command="{Binding SomeActionCommand}">
<ImageButton.Source>
<FontImageSource Glyph="{x:Static icons:IconFontGlyphNames.SomeActionSymbol}"
FontFamily="IconFontFamily"
Color="White"
Size="{StaticResource ToolbarIconFontSize}" />
</ImageButton.Source>
</ImageButton>
<!-- other declarations are skipped -->
</Grid>
</Shell.TitleView>
IconFontGlyphNames 类声明如下所示:
public static class IconFontGlyphNames
{
public const string SomeActionSymbol = "\uf234";
// other declarations are skipped
}
我使用这种方法设置图标和文本的字体大小,它在 Android 和 iOS 平台上运行良好。
更新#1。解释 `Shell.TitleView` 位置。
Shell.TitleView
位于此处:
<ContentPage>
<Shell.TitleView>
<!-- Shell title view elements go here -->
</Shell.TitleView>
<ContentPage.Content>
<!-- Your page body elements go here -->
</ContentPage.Content>
</ContentPage>
关于c# - Xamarin Forms 使用字体大小缩放组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74443797/