【问题标题】:Set AutomationProperties to back button of the navigation bar to avoid TalkBack's "Unlabeled button"将 AutomationProperties 设置为导航栏的后退按钮,以避免 TalkBack 的“未标记按钮”
【发布时间】:2020-05-15 06:05:30
【问题描述】:

我正在使用 Xamarin.Fomrs 开发一个可访问的跨平台应用程序。我正在使用NavigationPage 来管理导航。当我在第二个页面中并想使用导航栏中的按钮返回时,TalkBack 会显示:“未标记的按钮”。

如何为这个按钮设置AutomationProperties?主要目标是根据当前视图设置不同的帮助文本。有没有可能

【问题讨论】:

  • 您需要在每个平台中对NavigationRenderer 进行子类化,从那里获取图像并设置其AutiomationProperties
  • 谢谢 Mihail,我不知道NativagionRenderer 是什么,但我会检查一下
  • @Jon 你好,如果在导航到下一页时使用NavigationPage,将会有一个默认的后退按钮。并单击返回按钮将返回上一页。您可以分享一些代码来解释您的问题。
  • @JuniorJiang-MSFT 您好,是的,后退按钮会自动出现,这没有问题。问题是当您在 Android 设备中激活 TalkBack 时,允许盲人使用该应用程序,但必须在每个有趣的视图中设置 AutomationProperties。当视图聚焦时,TalkBack 会读取这些属性,并且“默认后退按钮”会像“未标记按钮”一样读取,因为无法直接访问按钮来设置属性。

标签: xamarin.forms accessibility navigationbar back-button


【解决方案1】:

我用这个渲染器实现了我的目标:

[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";
        }
    }
}

现在反对说明选择“返回”后按按钮。

【讨论】:

    【解决方案2】:

    接受的答案对我不起作用。对我有用的(Xamarin 5、Android 11)是这样的:

    [assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageCustomRenderer))]
    namespace CustomRenderers
    {
        public class NavigationPageCustomRenderer : NavigationPageRenderer
        {
            public NavigationPageCustomRenderer(Context context) : base(context) { }
    
            public override void AddChildrenForAccessibility(IList<Android.Views.View> views)
            {
                base.AddChildrenForAccessibility(views);
    
                var backButton = views.FirstOrDefault(x => x is Android.Widget.ImageButton && string.IsNullOrEmpty(x.ContentDescription));
                if (backButton != null)
                {
                    backButton.ContentDescription = "Go back";
                }
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      对于 AndroidX,我使用了以下内容:

              protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
              {
                 base.OnElementChanged(e);
      
                 Activity context = (Activity)this.Context;
                 var toolbar = context.FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar);
      
                 if (toolbar != null)
                 {
                    toolbar.NavigationContentDescription = "Go back";
                 }
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多