视图的大标题

问题描述 投票:0回答:1

我有xamarin。形成几个视图的应用程序,其中一个视图的标题为42个字符。有没有办法让它在视图中显示而不会遗漏任何字符。当我尝试这个渲染器时,我得到适用于每个视图的字体大小,但是我需要显示那个标题为42个字符的特定视图。

    [assembly: ExportRenderer(typeof(CustomNavigationPageControl), typeof(CustomNavigationPageRenderer))]

namespace ALCInspection.Droid.Dependecies
{
    public class CustomNavigationPageRenderer : NavigationPageRenderer
    {
        public CustomNavigationPageRenderer(Context context) : base(context)
        {
        }


        private Android.Support.V7.Widget.Toolbar _toolbar;

        private Android.Support.V7.Widget.Toolbar toolbar;


        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);
            if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
            {
                toolbar = child as Android.Support.V7.Widget.Toolbar;
                toolbar.ChildViewAdded += Toolbar_ChildViewAdded;
                var a = toolbar.ChildCount;

            }

        }

        void Toolbar_ChildViewAdded(object sender, ChildViewAddedEventArgs e)
        {
            var view = e.Child.GetType();
            if (e.Child.GetType() == typeof(Android.Support.V7.Widget.AppCompatTextView))
            {
                var textView = e.Child as Android.Support.V7.Widget.AppCompatTextView;
                textView.TextSize = 16;

                toolbar.ChildViewAdded -= Toolbar_ChildViewAdded;

            }
        }
    }
}

public class CustomNavigationPageControl : NavigationPage
{
    public CustomNavigationPageControl(Page root) : base(root)
    {
    } 
}

 public static async Task NavigateToAsyncToSmallTitleView(Page firstPageToNavigate, INavigation navigation = null)
    {
        try
        {
            if (navigation == null)
            {                  
                navigation = ((CustomNavigationPageControl)Application.Current.MainPage).Navigation;
            }
            await navigation.PushAsync(firstPageToNavigate, false);  
        }
        catch(Exception exception)//exception specified cast is not valid
        {

        }
    }

我称之为

 await Helper.NavigateToAsyncWithSmallTitle(new OtherViwq());

我在搜索上面带了上面的代码但它抛出了指定的强制转换异常。

android xamarin.forms navigation
1个回答
0
投票

根据this question,您需要使用自定义渲染器。看看hereduplicate question herehere。希望能帮助到你..

© www.soinside.com 2019 - 2024. All rights reserved.