问题描述
我正在按钮和标签中放置图标,但这是结果:
会显示图标,但会更改文本。如何在不更改文本的情况下显示图标?
@Configuration
class WebConfig implements WebMvcConfigurer {
HttpMessageConverter messagePackMessageConverter() {
MediaType msgPackMediaType = new MediaType("application","x-msgpack");
return new AbstractJackson2HttpMessageConverter( new ObjectMapper( new
MessagePackFactory()),msgPackMediaType) {
};
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters)
{
converters.add(messagePackMessageConverter());
}
}
解决方法
Button
可以有Text
和一个ImageSource
和FontImageSource
:
ContentLayout
设置图像相对于文本的位置和间距,其默认值显示在XAML下方。
可能的位置值为Left
,Right
,Top
,Bottom
。
位置值为Left
或Right
的文本垂直居中。
位置值为Top
或Bottom
时,文本水平居中。
<Button Text="fa-list" ContentLayout="Left,10">
<Button.ImageSource>
<FontImageSource Glyph="" FontFamily="{StaticResource FaRegular4}"/>
</Button.ImageSource>
</Button>
Label
可以有一个或多个Span
:
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="f0A4 " />
<Span Text="" FontFamily="{StaticResource FaRegular4}" />
<Span Text=" f0A5 " />
<Span Text="" FontFamily="{StaticResource FaRegular4}" />
</FormattedString>
</Label.FormattedText>
</Label>
,
我认为最简单的方法是改用按钮Image。
下载图标并将其添加到iOS中的“资源”文件夹和Android中的Drawable中。
然后按如下所示在您的按钮中使用它:
<Button Text="Edit" ImageSource="edit_icon" />
顺便说一句,您需要将按钮的字体更改为其他字体或保留默认字体。
,我可以想到的一种解决方法是将图标和文本分开:
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" BackgroundColor="Purple">
<Button Text="" FontFamily="FontAwesome" TextColor="White" WidthRequest="25" HorizontalOptions="Center"
VerticalOptions="Center" />
<Label Text="Load Items" TextColor="White" WidthRequest="90"
HorizontalOptions="Center"
VerticalOptions="Center" />
</StackLayout>