-3

I've been trying to put a Lock Symbol in the textview of an activity. However what I have used from this website did not seem to work.

<TextView
    android:id="@+id/lockTextView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" 
    android:text="\uD83D\uDD12"/>

EDIT

As you see from my example I had wanted to set the 'unicode' representation of the lock symbol as text in the 'TextView' in the xml. However, the only way to show the lock symbol was by setting it in code.

I am looking for a way to do this in the xml OR an explanation why this way acts different from setting it in code.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Totumus Maximus
  • 7,543
  • 6
  • 45
  • 69

1 Answers1

0

You can add drawable by the following ways,

txtview.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image, 0, 0, 0);

Also you can use with xml,

<TextView
    android:id="@+id/id_locText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:drawableLeft="@drawable/img_lock"
    android:drawablePadding="5dp"
    android:singleLine="true"
    android:text="@string/name"/>

Other than this, better you can also use image as background of textview

android:background="@drawable/ic_lock_background"

For programmatically : Try with below updated code,

Adding the Unicode character within java to the String in the XML file:

String str = "\uD83D\uDD12" + getContext().getString(R.string.your_string);
pradip_android
  • 283
  • 1
  • 3
  • 16