Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio enum left right bug? How to disable RTL warnings for whole project?

Android Studio should be known for those in most cases just aggravating Lint "Using left/right instead of start/end attributes" warnings. I'm using Android Studio 0.8.9, but the following problem was also present in earlier versions: If you add this ultra-minimal snippet anywhere in your code

public enum BiteMeLint {
    LEFT
}

Android Studio shows the warning

Use "Gravity.START" instead of "Gravity.LEFT" to ensure correct behavior in right-to-left locales.

This also happens for the constant RIGHT, though it suggests to use Gravity.END in that case. Now I'm a developer who likes to keep his code completely clean of any warnings, either by complying or, if that's not possible, by suppressing and putting a "todo" or "fixme" where necessary. Here, since I'm using "LEFT" and "RIGHT" as constants for actual directions, the warning is obviously a bug. Sadly, adding

@SuppressLint("RtlHardcoded")

doesn't remove the warning. So how do I remove this joke of a warning? And now that I'm asking, can I somehow completely disable RTL warnings for a project I'm sure will never launch in a right-to-left locale?

like image 512
0101100101 Avatar asked Sep 29 '14 11:09

0101100101


2 Answers

According to this issue tracker, it is a bug which was fixed in Android Studio 0.8.10 recently.

The option to disable this inspection can be found under Project Settings | Inspections | Android Lint | Unsing left/right instead of start/end attributes. So you can simply disable it for the whole project by unchecking the box.

like image 112
Darek Kay Avatar answered Sep 20 '22 13:09

Darek Kay


Android Studio 3

Go to File > Settings > Editor > Inspections > Android > Lint > Internationalization > Bidirectional Text.

Then uncheck Using left/right instead of start/end attributes.

But...

You may not want to actually disable the warning. It is there for a reason. Read what the Android Studio description says about it:

Using Gravity#LEFT and Gravity#RIGHT can lead to problems when a layout is rendered in locales where text flows from right to left. Use Gravity#START and Gravity#END instead. Similarly, in XML gravity and layout_gravity attributes, use start rather than left.

For XML attributes such as paddingLeft and layout_marginLeft, use paddingStart and layout_marginStart. NOTE: If your minSdkVersion is less than 17, you should add both the older left/right attributes as well as the new start/right attributes. On older platforms, where RTL is not supported and the start/right attributes are unknown and therefore ignored, you need the older left/right attributes. There is a separate lint check which catches that type of error.

(Note: For Gravity#LEFT and Gravity#START, you can use these constants even when targeting older platforms, because the start bitmask is a superset of the left bitmask. Therefore, you can use gravity="start" rather than gravity="left|start".)

like image 42
Suragch Avatar answered Sep 23 '22 13:09

Suragch