0

I put the following command in my layout, plus it works only in Ios and the android appears the title and not the image

         <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="teste.Views.HomePage" Title="titulo 1"
         NavigationPage.TitleIcon="logo.png">

This command 'NavigationPage.TitleIcon="logo.png"' works on ios, but does not work on android, do you have any command to put on android to make that image appear in the center?

enter image description here

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
José
  • 165
  • 1
  • 12

1 Answers1

0

You could make a Toolbar natively just for Android; iOS would continue to be handled by what you've done and Android will be handled by itself:

  1. Make a Toolbar XML resource, something along the lines of this*. This goes in the 'Resource/Layout' folder, I named mine 'Toolbar.axml'
<android.support.v7.widget.Toolbar
   style="@style/ToolBarStyle"
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="?attr/colorPrimary"
   android:minHeight="@dimen/abc_action_bar_default_height_material">

    <ImageView
        android:layout_width="wrap_content"
        android:contentDescription="@string/logo"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/ic_launcher"/>

 </android.support.v7.widget.Toolbar>
  1. Set the toolbar resource in the MainActivity onCreate method.

ToolbarResource = Resource.Layout.Toolbar;

* I used the example here: https://stackoverflow.com/a/27534791/1240523. There are also other answers which modify the tool bar to match what you are looking for.

RobVoisey
  • 1,083
  • 15
  • 24
  • This is correct, but I'm using this.Navigation.PushAsync and the details page when it is triggered instead of being written. Back in the top appears the logo as the button to go back to the main page, this happens only on android. What has to be changed? – José Aug 10 '17 at 20:13
  • Sorry, I don't quite understand that you're saying. If you need to change the Toolbar at run time, you'll need to use a `CustomRenderer` for the Page. – RobVoisey Aug 11 '17 at 09:46