2017-08-10 37 views
0

我在我的佈局把下面的命令,再加上它只能在iOS和Android的出現的標題,而不是像如何把圖像在上面的標誌在我的Android應用

  <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"> 

此命令'NavigationPage.TitleIcon =「logo.png」'適用於ios,但在android上不起作用,您是否有任何命令放在android上使該圖像出現在中心?

enter image description here

+0

上面的圖像是一個示例圖像,而不是我的項目 –

回答

0

你可以做一個工具欄本身只是針對Android; iOS版將繼續由你做了什麼和Android將自行處理的處理方式:

  1. 做一個工具欄XML資源,沿東西這行*。這正好在 '資源/佈局' 文件夾中,我將其命名 '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> 
  • 設置在MainActivity onCreate方法工具欄資源。
  • ToolbarResource = Resource.Layout.Toolbar;

    *我在這裏使用的示例:https://stackoverflow.com/a/27534791/1240523。還有其他的答案修改工具欄以匹配你正在尋找的東西。

    +0

    這是正確的,但我在使用this.Navigation.PushAsync和詳細信息頁面時觸發而不是寫入。返回頂部出現的標誌作爲返回到主頁面的按鈕,這隻發生在android。什麼需要改變? –

    +0

    對不起,我不太明白你的意思。如果您需要在運行時更改工具欄,則需要爲頁面使用「CustomRenderer」。 – RobVoisey

    相關問題