I am building a Android and iOS app and wanted to use sans-serif front on a label but I dont see it on the http://iosfonts.com/. I see the front on https://fonts.google.com/?query=sans+serif but I am not sure what to use in the FontFamily tag?
<Label Grid.Row="1" Text="TestFrontFamily" LineBreakMode="WordWrap" FontSize="20" HorizontalOptions="Center" VerticalOptions="End" TextColor="White" FontFamily="sans-serif"></Label>
As a general rule, you should never change the font in your app. Use the system default font. This is what people are used to on their phone, and opening an app that uses a different font is jarring.
With that out of the way, you need to download the font file, either otf or ttf, and save it somewhere in each android and iOS project. Then the font family points at that file. For example:
Font file placed in Fonts folder:
iOS: FontAwesome5ProLight
Android: Fonts/fa5-pro-light-300.otf#FontAwesome5ProLight
For iOS you simply need the font family name to be the name of the font to use. For Android, you need to include the path relative to the android csproj file as well as the font file name followed by # and the font name.
See Xamarin Font Documentation for further information.
Related
I want to display some .gif icons on android project.. but many icons not moving.. I don't know why.. ?
I have a <Image/> with propertie: IsAnimationPlaying="True" and this work only for three gifs and other gifs not moved...
<Image Source="rain.gif"
IsAnimationPlaying="True"
WidthRequest="40"
HeightRequest="40"
Grid.Row="2"
Grid.Column="1"/>
In drawable folder I set all gifs to AndroidResource property but this not work..
Аnd after all, the icon is not the one I placed in drawable folder.
I set rain.gif who is not this one from the screenshot.
This is real icon rain.gif:
So the first three .gif icons is moved and worked (thermometers), other .gif icons not worked and rain.gif is different I don't know why ?
Could it be that the problem is that I have the same name with different extensions in drawable folder, like: rain.jpg rain.png...
I try many times to clear the project and build again and again but not worked for me..
Becasue Android doesn't have built-in support for loading gif into ImageViews.
You could display gif with some commonly used third-party controls.
Like FFImageLoading
<ffimageloading:SvgCachedImage Source="rain.gif" WidthRequest="40"
HeightRequest="40"
Grid.Row="2"
Grid.Column="1"/>
If I have a label, how do I get it to adjust to larger font sizes as expressed by a user's accessibility settings? I have scoured the Internet and can't find any articles related to this issue.
<Label FontSize="14" />
use Named Font Sizes
Body
Caption
Default
Header
Large
Medium
Micro
Small
Subtitle
Title
On iOS and Android, named font sizes will autoscale based on operating
system accessibility options.
I'm creating a Xamarin.Form app for Android and iOS, and some users replace system default font with their own fonts, and FontSize property in Xaml doesn't work with these fonts, and these fonts are not so readable in my App. 1. So can I force the font used in my App to be system default font even the user changed font in their system config page?
2. If I can't do the above, can I set the FontFamily of all controls in my App with a text property to the font I included in my Android and iOS assets folder globally once and for all?
I've searched for some global font solution, but found no Xamarin.Form solution, and some solution seems to have been outdated.
For now, I set the FontFamily for controls one by one like this:
<Button FontFamily="{OnPlatform Android=xiaozuan.ttf#xiaozuan}"/>
There are so many controls that I can't really do this one by one...
Any clue or help would be appreicated!
So can I force the font used in my App to be system default font even the user changed font in their system config page?
If you want to change default fontfamily, I think you can override default font using custom font.
https://www.infragistics.com/help/xamarin/overriding-default-font
If I can't do the above, can I set the FontFamily of all controls in my App with a text property to the font I included in my Android and iOS assets folder globally once and for all
You can use Global Styles in Xamarin.Forms to change all element in your project, here is changing the font of all label.
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Label">
<Setter Property="FontFamily" Value="sans-serif" />
<Setter Property="FontSize" Value="20" />
</Style>
</ResourceDictionary>
</Application.Resources>
I have some icons on my xamarin forms project. I need a circle background for my icon. See the screenshot below:
I tried Xam.Plugins.Forms.ImageCircle plugin and tried Framelayout. Imagecircle plugin only cropping the icon and Framelayout gives a rounded corner layout. Nothing gives me a perfect circle background. I go through the FFImageloading documentation, but which is also the same as Imagecircle plugin.
Image code
<Image
Source="ic_group_fill_xx.png"
WidthRequest="25"
HeightRequest="25"/>
Is there any way to achieve this feature?
I usually prefer to make an icon that by default has a circle in it, doesn't make sense to add extra code for something that can be done for free.
There is great document by Android on working with Images for Android applications which can be found here, you can also use Android Asset Studio for creating awesome images.
I normally use an ImageButton for this (and because of the clicked property you don't need to use Gesture Recognizers for detecting taps)
The code below gives me a perfect circle on Android & iOS
<ImageButton Source="icon_name"
BackgroundColor="Blue"
HeightRequest="60"
WidthRequest="60"
CornerRadius="30"
Padding="15"
Clicked="Btn_Clicked" />
The image below is from my app, the image button is inside AbsoluteLayout and the icon is 64x64
Use the ImageCircle.Forms.Plugn plugin which I am already using it,
Import namespace like below,
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
And use the image control like below sample,
<controls:CircleImage
Source="{Binding ProfileImage}"
HorizontalOptions="Start"
VerticalOptions="Center"
WidthRequest="40"
Aspect="AspectFill"
BorderColor="#B8BCC9"
BorderThickness="1"
HeightRequest="40" />
I have a Xamarin Forms page with a toolbar item like this:
<ToolbarItem Name="Cancel">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource" WinPhone="button_cancel.png" />
</ToolbarItem.Icon>
</ToolbarItem>
This is using a bitmap for showing a cancel icon in Windows Phone. But in Windows Phone there is already predefined icons like this (in the Segoe UI Symbol font). Can I use them instead of bitmaps?
You can make a custom renderer for a NavigationPage which then replaces normal images sources to the native one while using custom fonts. More here (examples are for Android and iOS but should be easily adopted to Windows too: https://forums.xamarin.com/discussion/17278/custom-font-in-xamarin-forms-font-awesome/p1