Is there a way I can suppress individual warnings about hardcoded strings in layout files?
I often put placeholder text into TextViews so that I can see them in layout at design time. The downside of this is getting a ton of these warnings about hardcoded strings. But without them I wouldn't see the TextViews at all in the layout.
You can add the following to the text view element:
tools:ignore="HardcodedText"
Example:
<TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is a hardcoded text" tools:ignore="HardcodedText" />
Note there is a shortcut in Eclipse for adding this easily: just press CTRL + 1 and select the relevant option.
Unfortunately, I couldn't find a way to do this for a whole layout, you will have to do it for each element.
Note that you must also add the xmlns:tools="http://schemas.android.com/tools
attribute to the root element
The other way is to use tools:text
instead of android:text
:
<TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:text="This is a hardcoded text" />
Note that you must also add the xmlns:tools="http://schemas.android.com/tools
attribute to the root element
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