Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

any way to suppress warnings about "hardcoded strings" in layout files?

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.

like image 361
ycomp Avatar asked Feb 20 '12 13:02

ycomp


2 Answers

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

like image 131
Clint Eastwood Avatar answered Oct 09 '22 11:10

Clint Eastwood


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

like image 34
Romain Piel Avatar answered Oct 09 '22 10:10

Romain Piel