Android xml Text attribute textview cannot accept value "<" as value

I cannot dial

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

      

it gives error

Error: (317) XML parsing error: malformed (invalid token)

+3


source share


5 answers


Do it in XML:

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

      



Program:

button.setText("<");

      

+3


source


You need to avoid text, xml has specifics 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 "<"

with"&lt;"



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

      

+3


source


If you want to set ">" symbol in XML file, you can do the following.

1) Using CDATA you can achieve this.

2) Dynamically you can set the button as follows

yourButton.setText("<");

      

or you can use

android:text="&lt;"

      

Hope this helps you.

+1


source


Use &lt;

for <

, &gt;

for >

and &amp;

for &

.

Create a string in your values ​​folder.

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

      

And use like this -

android:text="@string/lessThanSymbol"

      

+1


source


Try this code. You just need to set the height and width. Just copy and paste this code into your xml.

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

      

0


source







All Articles