0

enter image description hereThis is my xaml code:

ContentPage.ToolbarItems ToolbarItem Text="+" Priority="0" Order="Primary" Command="{Binding PrikaziCommand}" ToolbarItem ContentPage.ToolbarItems

How to change color of text through xaml code to all platform?

Srki92
  • 19
  • 7
  • Please post your codebase sample. – Blu Jan 31 '20 at 10:06
  • Please refer: https://stackoverflow.com/questions/45323451/change-color-of-toolbaritem-in-xaml – MShah Jan 31 '20 at 10:14
  • I do not see any XAML!!!! – FreakyAli Jan 31 '20 at 10:20
  • I see that link MShah,but dont help me,need me in xaml to i can specific to all platform this is only for android,but me android works fine....I place xam code but dont see probably because tag,i edit code without tag now.... – Srki92 Jan 31 '20 at 10:21
  • @Srki92 Why dont you use navigation.title view – Anand Feb 01 '20 at 03:56
  • We could not set the ToolbarItem text color directly in xaml because there is no such an API . The workaround is set it in specific platforms like the solution in the link . – Lucas Zhang Feb 03 '20 at 03:29

1 Answers1

0

If you want to change your toolbar textcolor, you can use Navigation.Titleview

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TitleViewSample"
             x:Class="TitleViewSample.MainPage">

      <NavigationPage.TitleView>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <Label Text="Your Title" Grid.Column="0" TextColor="White" FontSize="Large" VerticalOptions="Center" HorizontalOptions="FillAndExpand"></Label>

            <StackLayout Grid.Column="1" HorizontalOptions="EndAndExpand" Orientation="Horizontal" Margin="0,5,5,5">
                <Label Text="?" FontSize="Large" TextColor="Red" Margin="10" ></Label>
                <Label Text="+" FontSize="Large" TextColor="Green" Margin="10" ></Label>
            </StackLayout>
        </Grid>
</NavigationPage.TitleView>


</ContentPage>

If you want to change the toolbar color add this code when navigating to your specific page

 MainPage = new NavigationPage(new YourPage());
((NavigationPage)MainPage).BarBackgroundColor = Color.FromHex("#19110F");

Result

Anand
  • 1,866
  • 3
  • 26
  • 49
  • NavigationPage.TitleView and ContentPage.ToolbarItems are two different things.ContentPage.ToolbarItems dont have TextColor.... – Srki92 Feb 03 '20 at 08:06
  • yes. You can use NavigationPage.TitleView instead of contentpage.Toolbar items – Anand Feb 03 '20 at 08:23
  • When i try to place 2 label tag in NavigationPage.TitleView ,C# said that the property'TitleView' is set more than once. – Srki92 Feb 03 '20 at 09:51
  • @Srki92 What items do you want to be in your toolabr? – Anand Feb 03 '20 at 09:55
  • @Srki92 I edited my answer. You should place your controls inside a stacklayout or frame – Anand Feb 03 '20 at 09:57
  • I try with stack layout in title view,but still same mistake.And that solution to place in Navigation page title view dont solution for me because i must place it with horizontal placement 2 iteams.With Toolbar iteams i dont worry to placement 2 iteams.I want to place ? sign for inromation,and + for search iteam,but i have problem with UWP platform ,item dont see because is white on default,that i want to change on something other color to be visible.... – Srki92 Feb 03 '20 at 10:19
  • Can you post your xaml – Anand Feb 03 '20 at 11:10
  • If you want to change the toolbar color, MainPage = new NavigationPage(new Page1()) { BarBackgroundColor = Color.Gray }; – Anand Feb 03 '20 at 11:13
  • i add screenshot image on first question on the top. – Srki92 Feb 03 '20 at 12:03
  • @Srki92 Please check my updated answer. You can use image at the place of labels – Anand Feb 03 '20 at 12:23
  • its worked thank you,i try your solution with NavigationPage.TitleView,but i have another problem when implement that,i must be carefull with image size...and that is bigger job... – Srki92 Feb 04 '20 at 14:18
  • @Srki92 Glad it helped. Can you accept this answer? – Anand Feb 05 '20 at 04:11
  • @Srki92 You should use height request and widthrequest of image as 30 – Anand Feb 05 '20 at 04:12