The main content

For the six types of Android Lint rules supported by Android Studio, this article mainly explains the 14 items included in the Accessibility and Internationalization types. The main content is document translation, with some of your own comments.

Figure a overview

Accessibility

Accessibility checks, except for the first item, are more like preparations for some automated tools and do not affect the operation of the APP.

ClickableViewAccessibility

ClickableViewAccessibility

Accessibility of clickable Views: If the View overrides onTouchEvent or uses OnTouchListener without implementing performClick and calling it when it detects a click, the View may not handle the accessibility operation properly. Ideally, the logic for handling a click would be in View#performClick, because some accessibility service calls performClick when a click occurs.

ContentDescription

ContentDescription – 1

Non-text Widget description:

  • First, non-text widgets such as ImageViews and ImageButtons should use the contentDescription attribute to specify the text to describe the Widget so that screen readers and other accessibility tools can fully describe and understand the user interface.
  • Second, if a non-text Widget is just a decoration on the user interface that does not display anything or accept any user action, there is no need to provide descriptive contentDescription property text. Instead, suppress lint alerts using the tool property tools:ignore=”ContentDescription”.
  • Third, you cannot set the hint and contentDescription at the same time for text widgets, otherwise the hint will not be displayed in the interface. Just set the hint.

Make apps more accessible

ContentDescription – 2

GetContentDescriptionOverride

Overwriting the non-text Widget description method getContentDescription: Overwriting the View’s getContentDescription method may prevent some accessibility services from properly navigating the content exposed by the View. Instead, setContentDescription is called when the content description needs to change.

KeyboardInaccessibleWidget

KeyboardInaccessibleWidget – 1

Keyboard unavailable Widget: If a Widget is declared clickable but not focusable, the Widget is not accessible through the keyboard, setting focusable=true is required.

KeyboardInaccessibleWidget – 2

LabelFor

LabelFor – 1

Missing accessible tags: Editable controls such as EditText should assign the hint attribute, or use the labelFor attribute to specify a label control for the EditText if minSDKVersion is greater than or equal to 17. The label control can be a text control with a text property specified, such as TextView, or a non-text control with a contentDescription property specified, such as ImageView.

LabelFor – 2

Ignore this lint check if the specified TAB control, such as TextView, is in another Layout file and uses the Layout property to refer to the same layout file as the EditText.

LabelFor – 3

Internationalization

ByteOrderMark

I looked up the ByteOrderMark, or BOM, which refers to some markup character. This problem is usually caused by copying characters between files in different encoding formats or editing files on certain file systems.

In-file BOM alerts: Lint marks the BOM character contained in the file. Because in the Android project we expect to use UTF-8 to encode files and characters. BOM characters are not required for UTF-8, and some tools do not properly handle text with BOM characters.

BOM error check, UTF8 better not to bring BOM

EnforceUTF8

EnforceUTF8

Resource file encoding format non-UTF-8: XML files support a wide range of encoding types. However, some tools cannot properly encode certain types of files, and UTF-8 is a widely supported encoding type in Android applications. Encoding files using UTF-8 prevents strange problems when dealing with non-ASCII characters. In particular, Gradle merges xmL-type resource files with the preassumption that the files are encoded using UTF-8.

HardcodedText

HardcodedText

Hardcoded text properties: Do not set text property values for text controls directly in layout files or code.

  • Using the same text multiple times in different places can cause multiple changes if the text needs to be modified.
  • An APP cannot provide a list of translations for a new language, but there are many tools that can do this quickly.
  • It is a good idea to define the text value of the text attribute in the string.xml file for internationalization extension.

SetTextI18n

SetTextI18n

TextView internationalization: In the call TextView. SetText () to TextView assignment, cannot use Number. The toString () such as the Integer. ToString (mProfile. GetLeftStarCount ()) assign Numbers to a string value, Because number.tostring () does not handle delimiters and locale-specific numbers correctly.

It is recommended to use string.format () to specify appropriate placeholders for assignment.

Textview.settext () cannot be used directly with text, as described in HardcodedText. This checking can be disabled by using @SuppressLint(“SetTextI18n”) in code.

RelativeOverlap

RelativeOverlap

RelativeOverlap means that the two widgets within a RelativeLayout in the same horizontal direction are located on the left and right sides of the layout without limiting the length of the widgets. As the content grows, the distance between the widgets shrinks and eventually some widgets overlap. So, control the boundaries.

Bidrrectional Text Bi-directional Text

RtlEnabled

Using the RTL attribute on API 17 or later requires setting Android :supportsRtl=”true” in the application TAB of the manifest file. Android :supportsRtl=”false” if you have already started adding RTL properties to your layout file but are not using RTL to completely replace the old properties, you can avoid Lint by setting Android :supportsRtl=”false”.

RtlCompat

RtlCompat

API 17 provides a textAlignment property to the text control to control the alignment of horizontal text. However, if your APP supports a version smaller than API 17, you must set gravity or layout_gravity as the textAlignment property value is ignored on older systems.

RtlHardcoded

Force direction setting: the use of Gravity in text alignment, and control the alignment. LEFT/Gravity. The RIGHT way to specify in the LEFT or the RIGHT alignment, or in writing from RIGHT to LEFT writing disturbance to the country or region. Using Gravity. START/Gravity. END can solve this problem. Similarly, when setting gravity/layout_gravity in the layout file, use start/end instead of left/right.

The attributes paddingLeft/paddingRight and layout_marginLeft/layout_marginRight also need to be replaced with paddingStart/paddingEnd and layout_marginStart/layout _marginEnd.

If the minimum API version supported by your APP is less than API 17, you need to provide both the left/right and start/ End attributes, as the start/ End attributes are ignored on older systems.

RtlSymmetry

Margin | padding left and right sides is symmetrical: if one side of the a layout object specified padding or margin, you should specify the same to the other side the size of the padding or margin.

reference

  • Android Tools attribute reference