user1343673
user1343673

Reputation: 241

How to insert "<<" text in TextView?

I need to insert "<<" in android:text = "<<" but there are raise problem with:

Multiple annotations found at this line:
    - [I18N] Hardcoded string "<<", should use @string resource
    - The value of attribute "android:text" associated with an element type "Button" must not contain the '<' 
     character.

Can you tell me how can I insert << in xml file TextView text?

Upvotes: 12

Views: 4773

Answers (4)

Kishan Thakkar
Kishan Thakkar

Reputation: 755

You need to use the escaped version of <, which is <. Similarly, > should be replaced with > if required.

Upvotes: 0

MattMatt
MattMatt

Reputation: 2310

Use a string assignment, as the suggestions says. Create a string in strings.xml, like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    ..
    <string name="chevrons">&lt;&lt;</string>

</resources>

Then point the TextView to that, like this:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="20sp" 
    android:text="@string/chevrons"
>
</TextView>

Upvotes: 2

jarrad
jarrad

Reputation: 3292

You need to use the less-than XML escape character. See a full list here:

&lt;&lt;

Upvotes: 4

Kai
Kai

Reputation: 39651

Try &lt;&lt; instead of <<. You have to escape those characters because they influence your XML layout.

Upvotes: 21

Related Questions