My code showing icon only for iOS application. How can I add tab icon in NavigationPage.Icon for android too, xaml code
<NavigationPage Title="DairyTabPage">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="icon_tab"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<local:HomePage />
</x:Arguments>
</NavigationPage>
<NavigationPage Title="DairyTabPage" Icon="icon_tab">
<x:Arguments>
<local:HomePage />
</x:Arguments>
</NavigationPage>
This is what worked for me in case the other answer doesn't work for you:
<NavigationPage Title="Title">
<NavigationPage.Icon>
<OnPlatform x:TypeArguments="FileImageSource">
<On Platform="iOS" Value="tab_feed.png"/>
<On Platform="Android" Value="tab_feed"/>
</OnPlatform>
</NavigationPage.Icon>
<x:Arguments>
<views:ItemsPage />
</x:Arguments>
</NavigationPage>
Where I have put "tab_feed.png" into /Resources/drawable/tab_feed.png and included in the .Android project and rebuilt it so it regenerated the Resource.designer.cs file.
Related
I have a Maui app and want to style my app according to the platform I am on.
In a resource dictionary, I can use the following
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<OnPlatform x:Key="ButtonSize" x:TypeArguments="x:Double">
<On Platform="iOS" Value="14" />
<On Platform="Android" Value="16" />
</OnPlatform>
</ResourceDictionary>
What are the "Platform Strings" for Windows and Mac?
<On Platform="???" Value="16" />
according to the docs
Android
iOS
MacCatalyst
Tizen
WinUI
After I updated to Xamarin.Forms 5.0 this line of code has been broken:
<AbsoluteLayout.LayoutBounds>
<OnPlatform x:TypeArguments="Rectangle">
<On Platform="Android">0.5,0.49,0.4,0.5</On>
<On Platform="iOS">0.5,0.52,0.4,0.5</On>
</OnPlatform>
</AbsoluteLayout.LayoutBounds>
What can I do to fix it?
About setting AbsoluteLayout.LayoutBounds by platform, you can try to following code:
<AbsoluteLayout Margin="20">
<BoxView AbsoluteLayout.LayoutBounds="{OnPlatform Android='0,10,200,5', iOS='0,0,.5,.5'}" Color="Silver">
</BoxView>
</AbsoluteLayout>
I added a toolbar item of name refresh in tabbed page, below is the code of the tabbed page
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Xapp;assembly=Xapp"
mc:Ignorable="d"
x:Class="Xapp.HomePage">
<TabbedPage.ToolbarItems>
<ToolbarItem x:Name="Refresh" Text="Refresh" />
</TabbedPage.ToolbarItems>
<TabbedPage.Children>
<NavigationPage Title="report">
<x:Arguments>
<local:ReportPage>
<StackLayout>
<Label Text="In:" HorizontalOptions="FillAndExpand" />
<Label Text="{Binding CountIn}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="Out:" HorizontalOptions="FillAndExpand" />
<Label Text="{Binding CountOut}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="Date:" HorizontalOptions="FillAndExpand" />
<Label Text="{Binding createdon}" FontSize="Medium" FontAttributes="Bold" />
</StackLayout>
</local:ReportPage>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="history">
<x:Arguments>
<local:HistoryPage />
</x:Arguments>
</NavigationPage>
</TabbedPage.Children>
</TabbedPage>
the problem is the refresh appears two times in the toolbar as shown in the image below:
If the MainPage of App is a TabbedPage . You don't need to set it as NavigationPage . in App.
Modify the code in App.Xaml.CS
public App()
{
InitializeComponent();
MainPage = new HomePage();
}
Update
It is not a good design to navigate from a ContentPage to TabbedPage .
So modify the code to
App.Current.MainPage = new HomePage();
instead of page.Navigation.PushAsync(new HomePage());
I'm trying to assign different CornerRadius on iOS and Android like following:
<Frame
HasShadow="false"
Padding="10"
BackgroundColor="Red">
<Frame.CornerRadius>
<OnPlatform x:TypeArguments="x:Double">
<On
Platform="iOS">20</On>
<On
Platform="Android">30</On>
</OnPlatform>
</Frame.CornerRadius>
<Label
Text="Hello World" />
</Frame>
But getting a
Cannot assign property "CornerRadius": Property does not exists, or is not assignable, or mismatching type between value and property
I've tried x:TypeArguments="Thickness" and x:TypeArguments="x:Int32". Decompiling the Assembly it appears CornerRadius is of type float. However, there is no Float property in x namespace, I mean x:TypeArguments="x:Float" doesn't exists.
Any ideas what I'm doing wrong or this is a bug?
The CornerRadius type is a Single:
<Frame HasShadow="true" OutlineColor="Red">
<Frame.CornerRadius>
<OnPlatform x:TypeArguments="x:Single">
<On Platform="iOS" Value="20"/>
<On Platform="Android" Value="30"/>
</OnPlatform>
</Frame.CornerRadius>
<Frame.Content>
<Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
</Frame.Content>
</Frame>
Well I fell there is a syntax error here do something like this :
<Frame.CornerRadius>
<OnPlatform x:TypeArguments="x:Single">
<OnPlatform.Platforms>
<On Platform="iOS" Value="20" />
<On Platform="Android" Value="30" />
<On Platform="UWP" Value="30" />
</OnPlatform.Platforms>
</OnPlatform>
</Frame.CornerRadius>
Try this and in case it doesn't work kindly revert.
In Android, because the tab bar is at top, I don't need both title bar and tab bar to say which tab you're on.
This will hide the title bar for both platforms:
<TabbedPage>
<NavigationPage Title="Page 1">
<x:Arguments>
<local:Page1 NavigationPage.HasNavigationBar="false"/>
</x:Arguments>
</NavigationPage>
</TabbedPage>
try this:
<NavigationPage Title="Page 1">
<x:Arguments>
<Page>
<NavigationPage.HasNavigationBar>
<OnPlatform x:TypeArguments="x:Boolean">
<On Platform="Android" Value="False"></On>
</OnPlatform>
</NavigationPage.HasNavigationBar>
</Page>
</x:Arguments>
</NavigationPage>