C# 在主Xamarin项目的Android工具栏中显示/隐藏ImageView

C# 在主Xamarin项目的Android工具栏中显示/隐藏ImageView,c#,android,xamarin,xamarin.forms,xamarin.android,C#,Android,Xamarin,Xamarin.forms,Xamarin.android,这是我的情况。我有一个适用于iOS和Android的Xamarin应用程序,其中一个要求是第一个“主页”需要显示公司徽标,并将其放在工具栏中央。所有其他页面将显示页面标题而不是徽标。我必须自定义Android项目中的toolbar.axml文件,以便使用ImageView正确显示它,但现在它出现在每个页面上。我想知道的是,是否可以通过编程方式访问ImageView,并将其可见性属性设置为从共享的Xamarin项目可见,如App.xaml.cs文件或MainPage.xaml.cs文件?或者,如果

这是我的情况。我有一个适用于iOS和Android的Xamarin应用程序,其中一个要求是第一个“主页”需要显示公司徽标,并将其放在工具栏中央。所有其他页面将显示页面标题而不是徽标。我必须自定义Android项目中的
toolbar.axml
文件,以便使用
ImageView
正确显示它,但现在它出现在每个页面上。我想知道的是,是否可以通过编程方式访问
ImageView
,并将其可见性属性设置为从共享的Xamarin项目可见,如
App.xaml.cs
文件或
MainPage.xaml.cs
文件?或者,如果做不到这一点,是否可以在android项目中执行此操作,比如在
MainActivity.cs
文件中

下面是我的工具栏的外观

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:minHeight="?android:attr/actionBarSize">

<ImageView
    android:id="@+id/homeLogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo_file"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:paddingRight="50dp"
    android:scaleType="fitCenter"
    android:contentDescription="@string/app_name"
    android:visibility="gone"/>
</android.support.v7.widget.Toolbar>


我只需要能够将
homeLogo
的可见性设置为主页可见。这是我第一次真正深入到一个真正的Xamarin项目中,所以我在这里开始的时候就想清楚了。

你可以使用导航页面。TitleView然后定制你的风格

例如,如果希望让
homebogo
页面具有带有ImageView的工具栏,可以在
homebogo.xaml
中执行此操作:

<?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:App11"
         x:Class="App11.MainPage">

  //custom your style
  <NavigationPage.TitleView>
    <StackLayout > 
        <Image Source="ic_action_info.png" /> 
    </StackLayout>
  </NavigationPage.TitleView>


</ContentPage>

//定制你的风格

PS:需要Xamarin。Forms 3.2.0及更高版本

您可以使用导航页面。标题视图然后自定义您的样式

例如,如果希望让
homebogo
页面具有带有ImageView的工具栏,可以在
homebogo.xaml
中执行此操作:

<?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:App11"
         x:Class="App11.MainPage">

  //custom your style
  <NavigationPage.TitleView>
    <StackLayout > 
        <Image Source="ic_action_info.png" /> 
    </StackLayout>
  </NavigationPage.TitleView>


</ContentPage>

//定制你的风格

PS:需要Xamarin.Forms 3.2.0和更高版本

现在可以用了吗?现在可以用了吗?就是这样!当然,除去任何格式,它是巨大的,并且会被切断,但是功能是存在的。谢谢成功了!当然,除去任何格式,它是巨大的,并且会被切断,但是功能是存在的。谢谢