在Android中使用材料设计代码在手机中的可访问性

As part of Material Design Guidelines, Android added help for developers and designers to improve accessibility in Android apps. The topic of accessibility has become very important in web apps, this because indexing in search engines is improved when apps follow accessibility best practices. As this has not been enforced in mobile applications so much, we often forget it is key for inclusion and user experience. Accessibility in Android is very important and we will learn about it in this post.

作为《材料设计指南》的一部分,Android为开发人员和设计人员添加了帮助,以改善Android应用程序中的可访问性。 可访问性主题在Web应用程序中变得非常重要,因为当应用程序遵循可访问性最佳做法时,搜索引擎中的索引编制会得到改善。 由于在移动应用程序中并没有强制执行此操作,因此我们经常忘记这对于包容性和用户体验至关重要。 Android中的可访问性非常重要,我们将在本文中对此进行学习。

可访问性与可用性 (Accessibility vs. Usability)

Before diving into the details of accessibility in Android, I would like to clarify the distinction between accessibility and usability. Those two terms are usually used interchangeably, but they refer to different things.

在深入探讨Android中可访问性的细节之前,我想澄清可访问性和可用性之间的区别。 这两个术语通常可以互换使用,但是它们指的是不同的事物。

  • Accessibility: This is concerned with equivalent user experience for people with disabilities. If we implement this correctly, they can interact with tools without problems.

    辅助功能:这与残疾人的等效用户体验有关。 如果我们正确实现这一点,他们可以与工具进行交互而不会出现问题。
  • Usability: Is related to User Experience (UX). This is for all our users, not specifically for users with disabilities. Sadly, not all usability practices are inclusive with users that need accessibility.

    可用性:与用户体验(UX)有关。 这是针对我们所有用户的,而不是专门针对残疾用户的。 遗憾的是,并非所有可用性实践都包含在需要可访问性的用户中。

For a broader explanation on this topic, take a look at this article from the W3C.

有关此主题的更广泛的解释,请查看W3C的这篇文章。

One important thing to note is that disabilities are not necessarily permanent conditions. If for example, one of your users breaks an arm, you want to help them keep using your product while they go through recovery.

需要注意的重要一件事是,残疾不一定是永久条件。 例如,如果您的一位用户打断了胳膊,您想帮助他们在恢复过程中继续使用您的产品。

Image for post
Photo by Arteum.ro on Unsplash
Arteum.roUnsplash拍摄的照片

Android和Google中的辅助功能 (Accessibility in Android and Google)

Google has several guidelines regarding accessibility, Android as an open-sourced product from them is not behind. If you want to have a look at the Material Design Accessibility Guide, you can access it here.

Google有一些关于可访问性的准则,而作为开源产品的Android并不落后。 如果要查看《材料设计辅助功能指南》,可以在此处访问。

Android bases its accessibility guide in three main principles:

Android的可访问性指南基于以下三个主要原则:

明晰 (Clarity)

This is not just a topic of accessibility. In general, UX practices from the early days have been moved to clear interfaces. This can mean several things, but let’s look at three clarity examples:

这不仅仅是可访问性的主题。 通常,早期的UX实践已转移到清晰的界面。 这可能意味着几件事,但让我们看三个清晰的示例:

  1. Things are spread out enough through the screen so that elements don’t overlap.

    事物在屏幕上充分散布,因此元素不会重叠。
  2. Labels in buttons have a meaning that resembles the actions they execute.

    按钮中的标签的含义类似于它们执行的操作。
  3. Visual hierarchy, so that your eyes are guided by the content depending on what you should focus on.

    视觉层次结构,使您的眼睛由内容决定,具体取决于您应关注的内容。

坚固性 (Robustness)

I will take the definition of Cambridge dictionary for this:

我将为此采用剑桥词典的定义:

The quality of being strong, and healthy or unlikely to break or fail

坚强,健康或不太可能破裂或失败的质量

https://dictionary.cambridge.org/us/dictionary/english/robustness

https://dictionary.cambridge.org/us/dictionary/english/robustness

When talking about apps, the last three words are key: unlikely to break or fail. In this case, a robust app is unlikely to break when users require accessibility features, and they don’t fail to users with these needs. This means incorporating enough tools to fulfill these objectives. Luckily, most things are already included in the Android OS, and we just need to follow the guides.

在谈论应用程序时,最后三个词是关键:不可能中断或失败 。 在这种情况下,当用户需要可访问性功能时,功能强大的应用程序就不太可能损坏,并且不会满足用户的这些需求。 这意味着要结合足够的工具来实现这些目标。 幸运的是,大多数事情已经包含在Android OS中,我们只需要遵循这些指南即可。

特异性 (Specificity)

This refers to the platform you are using. If you are developing apps for Android phones, you usually think of input methods things like touch screen, keyboard, and maybe a mouse; but you should also look at things like input through voice commands.

这是指您正在使用的平台。 如果您正在开发用于Android手机的应用程序,则通常会想到输入法之类的东西,例如触摸屏,键盘,甚至可能是鼠标。 但是您还应该查看诸如通过语音命令输入的内容。

Image for post
Photo by Tim Marshall on Unsplash
Tim MarshallUnsplash拍摄的照片

Android开发人员的可访问性 (Accessibility for Android developers)

What we have discussed until now, is the base of accessibility in design, interface, and development. But let’s see how do developers implement this in order to make apps accessible.

到目前为止,我们所讨论的是设计,界面和开发中可访问性的基础。 但是,让我们看看开发人员如何实现此目的以使应用程序可访问。

The first general recommendation is to add a content description to all XML elements.

第一个一般性建议是向所有XML元素添加内容描述。

android:contentDescription="@string/descriptionOfElement"

There is only one exception to this, TextView, does not need a description.

只有一个例外,TextView不需要描述。

Also, note that sometimes you just add elements for spacing or a purpose not related to visual content. In this case, you should set the contentDescription, but with a value of null.

另外,请注意,有时您只是添加间距元素或与视觉内容无关的目的。 在这种情况下,应设置contentDescription,但其值为null。

按钮中的辅助功能 (Accessibility in Buttons)

Buttons are an important part of any mobile application. I have often heard people complain that it is hard to use their phones due to “fat fingers”. For this reason, and to help users with disabilities, it is important to consider the target size of a button.

按钮是任何移动应用程序的重要组成部分。 我经常听到人们抱怨说,由于“胖手指”,很难使用手机。 因此,为帮助残疾用户,重要的是要考虑按钮的目标尺寸

Android recommends a minimum of 48dp x 48dp for any button you are using. This can be achieved not only by the body of the button itself but through padding around the button. For example, you can have a button with a width of 32dp, and padding of 8dp to each side.

Android建议您使用的任何按钮至少为48dp x 48dp。 这不仅可以通过按钮本身的主体来实现,还可以通过按钮周围的填充来实现。 例如,您可以有一个宽度为32dp的按钮,并且每边的填充为8dp。

<Button 
android:layout_width ="wrap_content"
android:layout_height ="wrap_content"
android:minWidth ="32dp"
android:paddingRight="8dp"
android:paddingLeft="8dp"
... />
Image for post
Photo by John Schnobrich on Unsplash
John SchnobrichUnsplash上的 照片

编辑文字中的辅助功能 (Accessibility in Edit Text)

1. Focusable elements

1.重点突出的要素

<EditText 
android:id="@+id/accessibility_edit_text"
android:inputType="textPassword"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="true"> </EditText>

In the above code, the way of adding accessibility is through the last property. When you use your phone on a daily basis, the normal way of accessing an edit text is through touch, which is automatically handled. By adding the focusable you are telling accessibility devices that this is an editable item and if navigating with a keyboard or another device, the user can interact (focus) on it.

在上面的代码中,添加可访问性的方法是通过last属性。 每天使用手机时,访问编辑文本的通常方法是通过触摸进行自动处理。 通过添加可聚焦对象,您将告诉可访问性设备这是一个可编辑的项目,并且如果使用键盘或其他设备进行导航,则用户可以对其进行交互(聚焦)。

2. Hints

2.提示

It is also recommended to add hints in texts that are editable. These hints should have examples of valid input so that users can follow along.

还建议在可编辑的文本中添加提示。 这些提示应包含有效输入的示例,以便用户可以继续使用。

3. Associate each EditText with a Label

3.将每个EditText与一个标签相关联

I have seen many apps, even the ones I developed, that use the hint of an EditText as the label for it. The problem with this is that when the user inputs the text she no longer knows what the field was for.

我见过很多应用程序,甚至是我开发的应用程序,都使用EditText的提示作为其标签。 问题是当用户输入文本时,她不再知道该字段的用途。

It is encouraged to always pair up each EditText with a Label. Android studio suggests this every time you are creating a layout, it is marked as a warning, not an error. To clarify the relationship you should use the android:labelFor property.

建议始终将每个EditText与Label配对。 Android Studio每次创建布局时都建议这样做,它被标记为警告而不是错误。 为了阐明这种关系,您应该使用android:labelFor属性。

<TextView 
android:id="@+id/thisLabelDescribesTheEditText"
android:labelFor="@+id/thisIsTheEditText" .../> <EditText
android:id="@+id/thisIsTheEditText" ... />

Another important thing to remember is that the text of each label should be unique, otherwise, the user will not know to which one are you referring. For example, for a user with a screen reader, the position of the elements visually doesn’t give a hint and they will not know the difference between elements with the same name.

要记住的另一件重要事情是,每个标签的文本都应该是唯一的,否则,用户将不知道您要指向哪个标签。 例如,对于使用屏幕阅读器的用户,元素的位置在视觉上不会给出提示,并且他们将不知道具有相同名称的元素之间的区别。

Image for post
Photo by Dan Meyers on Unsplash
Dan MeyersUnsplash拍摄的照片

无障碍布局 (Accessible Layouts)

Similar to EditTexts that are focusable through input methods, view groups can also be focused. For screen readers, it is good to know which elements are grouped, that way when reading content, they can mention all the elements inside a layout as part of the same group. You can define this with the code below.

与通过输入法可聚焦的EditText相似,视图组也可聚焦。 对于屏幕阅读器,最好知道将哪些元素分组,这样在阅读内容时,他们可以将布局内的所有元素作为同一组的一部分提及。 您可以使用以下代码进行定义。

<LinearLayout 
android:id="@+id/this_is_a_container"
android:screenReaderFocusable="true" ...>

结语 (Wrapping Up)

These are the most important lines of code for Accessibility in Android. As you may see, it is not a lot of code to add, but have you considered the big difference it could make for some users? I hope you add this to your next project! Let me know in the comments below if you have any questions.

这些是Android中辅助功能最重要的代码行。 如您所见,添加的代码并不多,但是您是否考虑过它可能对某些用户产生很大的影响? 希望您将此添加到下一个项目中! 如果您有任何疑问,请在下面的评论中告诉我。

Until next time.

直到下一次。

Evana Margain Puig

伊凡娜·玛金·普伊格(Evana Margain Puig)

翻译自: https://medium.com/swlh/accessibility-in-android-with-material-design-code-in-mobile-d2d1df54a0b6

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值