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?
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.
Go to File > Settings > Editor > Inspections > Android > Lint > Internationalization > Bidirectional Text.
Then uncheck Using left/right instead of start/end attributes.
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".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With