【问题标题】:Change text of textview in custom toolbar in Xamarin Forms在 Xamarin Forms 的自定义工具栏中更改 textview 的文本
【发布时间】:2016-08-29 17:00:48
【问题描述】:

我正在尝试创建自定义工具栏。我关注了这个post。而且我可以更改工具栏,但我无法更改工具栏文本。这就是我正在做的事情

var toolbarTop = FindViewById<Toolbar>(Resource.Id.toolbar_top);
var titleTextView = toolbarTop.FindViewById<TextView>(Resource.Id.toolbar_title);
titleTextView.Text = title;

但标题没有改变。这里有什么问题?

顺便说一句:我正在更改每个新导航到不同页面的标题。不在活动创建上。

感谢您的帮助。

【问题讨论】:

    标签: xamarin xamarin.android xamarin.forms android-toolbar


    【解决方案1】:

    不要在“OnCreate”中这样做。在这里做

        public override void OnAttachedToWindow()
        {
           base.OnAttachedToWindow();
           Title = "Title Text";
        }
    

    【讨论】:

    • 工具栏被替换为自定义工具栏。标题不再起作用。我需要在自定义工具栏中更改 textview 的文本
    • 尝试更改文本视图但在 OnAttachedToWindow 函数中
    • 我正在使用 xamarin 表单。每当我导航到 Xamarin Forms 中的另一个页面时,我都需要更改文本。在 android 中它始终是 1 个活动。
    • 我很困惑。 FindViewById(Resource.Id.toolbar_top);看起来像是纯 Android 代码,而不是 Forms 代码。你怎么称呼它?在 PCL 中?
    • 我在 PCL 的 Activity 中调用它。我实现了服务,因此我可以在需要时从 PCL 调用此方法
    【解决方案2】:

    试试:

    Title = "Title Text";
    

    或者这可能会有所帮助: https://developer.xamarin.com/samples/monodroid/android5.0/Toolbar/

    【讨论】:

    • 工具栏被替换为自定义工具栏。标题不再起作用。我需要在自定义工具栏中更改 textview 的文本
    猜你喜欢
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 2019-06-15
    • 2016-03-08
    相关资源
    最近更新 更多