【问题标题】:How replace a navigation icon with a navigation title in xamarin forms如何用 xamarin 表单中的导航标题替换导航图标
【发布时间】:2017-07-27 13:52:25
【问题描述】:

我尝试在其中一个页面中向我的应用添加导航标题图标,我使用的代码是:

对于 iOS:

NavigationPage.SetTitleIcon(this, "icon.png");

对于 Android,我在 ToolBar.axml 中添加了一个 ImageView,如下所示:

<?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="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    <ImageView
        android:id="@+id/titleicon"
        android:src="@drawable/UstNameIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</android.support.v7.widget.Toolbar>

问题是,我希望我的导航图标在我的下一个页面中被禁用并放置一个标题而不是图标。

为此,我尝试过

对于 iOS:

NavigationPage.SetTitleIcon(this, null);


NavigationPage.Title="Title";

对于Android,如何实现导航标题的改变?

【问题讨论】:

  • 我的解决方案对您有用吗?
  • 嗨@Anoop,你找到解决方案了吗?

标签: xamarin.forms


【解决方案1】:

在 MainActivity.cs 中

[Activity (Label = "Todo.Android.Android", MainLauncher = true, Icon="@android:color/transparent")]

Title可以在xaml或者c#中设置Title属性

【讨论】:

    【解决方案2】:

    要更改文本,您只需通过 id 找到该元素,并设置标题:

    var toolbar = 
        FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); // it may be simplifed
        SetSupportActionBar(toolbar);
        toolbar.Title = "title";
    

    图片在toolbar.Logo下,你可以试试:

    toolbar.Logo = null;
    

    如果资源中有一些数据要放入,也可以使用:

    toolbar.SetTitle();
    toolbar.SetLogo();
    

    【讨论】:

    • 嗨@Karol,我也有同样的需求。我不明白如何放置您的代码?它适用于 Xamarin.Forms 吗?
    猜你喜欢
    • 2021-02-24
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2021-01-18
    相关资源
    最近更新 更多