Yunus Sımsıkı
Yunus Sımsıkı

Reputation: 55

android xml Textview text attribute cannot take '<' as value

I cannot type

   <Button
        android:id="@+id/del"
        android:text="<"
        android:textColor="#FFFFFF"/>

it gives an error

Error:(317) Error parsing XML: not well-formed (invalid token)

Upvotes: 3

Views: 665

Answers (5)

daniel.keresztes
daniel.keresztes

Reputation: 885

Do it like this in the XML:

<Button
    android:id="@+id/del"
    android:text="&lt;"
    android:textColor="#FFFFFF"/>

Programmatically:

button.setText("<");

Upvotes: 3

Luis Pereira
Luis Pereira

Reputation: 1521

You have to escape your text, the xml has particularities regarding escape text check this link https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML

So, in your case replace "<" for "&lt;"

&quot;   "
&amp;    &
&apos;   '
&lt;     <
&gt;     >

Upvotes: 3

Shoeb Siddique
Shoeb Siddique

Reputation: 2825

Use &lt; for <, &gt; for > and &amp; for &.

Please create string in your value folder.

<string name="lessThanSymbol">&lt;</string>

And use like this-

android:text="@string/lessThanSymbol"

Upvotes: 1

Chaudhary Amar
Chaudhary Amar

Reputation: 856

Try This Code.You just have to set the height & width. Just Copy and paste this code in your xml.

    <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:id="@+id/del"
               android:text="<"
               android:textColor="#FFFFFF"/>

Upvotes: 0

Nagaraju V
Nagaraju V

Reputation: 2757

If you want set ">" character in XML file you can do by following ways

1) By using CDATA you can achieve this.

2) Dynamically you can set to button as follows

yourButton.setText("<");

or you can use

android:text="&lt;"

Hope this will helps you.

Upvotes: 1

Related Questions