Search code examples
xamarin.formsaccessibilitynavigationbarback-button

Set AutomationProperties to back button of the navigation bar to avoid TalkBack's "Unlabeled button"


I'm developing an accessible cross platform application using Xamarin.Fomrs. I'm using NavigationPage to manage the navigation. When I am in a second page and I want to go back using the button in the navigation bar, TalkBack says: "unlabeled button".

How can I set AutomationProperties for this button? The main goal is to set different help texts depending on the current view. Is it possible


Solution

  • I achieved my goal with this renderer:

    [assembly: ExportRenderer(typeof(ContentPage), typeof(AndroidNavigationPageRenderer))]
    namespace SZukaldatzen.Droid.Renderers
    {
        public class AndroidNavigationPageRenderer : PageRenderer
        {
            public AndroidNavigationPageRenderer(Context context) : base(context)
            {
            }
    
            protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
            {
                base.OnElementChanged(e);
    
                Activity context = (Activity)this.Context;
                var toolbar = context.FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
    
                toolbar.NavigationContentDescription = "Go back";
            }
        }
    }
    

    Now TalkBack says "Go back" when back button is selected.