6

I'm trying to display a single Unicode character (an emoji) in a TextView, with a large(r) text size:

mEmojiTextView = (TextView) findViewById(R.id.emoji_text_view);
mEmojiTextView.setTextSize(200);
mEmojiTextView.setText("\uD83D\uDE01");

The character does not appear on the screen, and I get this error in logcat:

E/OpenGLRenderer﹕ Font size too large to fit in cache. width, height = 545, 513

The largest size that works is

mEmojiTextView.setTextSize(150);

and the Emoji character appears. It's not like it's full screen or anything, at this text size there is enough space on the screen for about 6 emoji characters.

I'm running the test on a LG Nexus 5 phone, with 1080 x 1920 resolution, running Android 5.1.1. I'm using minSdkVersion 11 and targetSdkVersion 23

I tried many workarounds found on StackOverflow and elsewhere:

mEmojiTextView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

<TextView android:layerType="software" ... />

<activity android:hardwareAccelerated="false" ... />

Nothing works.

Is there a way I can get it to work?

TechAurelian
  • 5,561
  • 5
  • 50
  • 65
  • try to use it with value string resources of android project – Androider Aug 30 '15 at 15:37
  • 1
    is there any reason you can't use scaleX/scaleY on the textView instead of increase the font size? – Gil Moshayof Aug 30 '15 at 15:45
  • @GilMoshayof Tried that (android:scaleX="4" android:scaleY="4" android:textSize="50sp"), doesn't show the caracter, and gives the same logcat error: "Font size too large to fit in cache. width, height = 722, 679" – TechAurelian Aug 30 '15 at 15:52
  • @GilMoshayof If I add android:layerType="software" it finally works (!), and the emoji appears, but it looks pixelated, like a bitmap image that was enlarged many times. – TechAurelian Aug 30 '15 at 16:02
  • and if you wrap the textview in a relative layout or some other container, and then scale up the container? – Gil Moshayof Aug 30 '15 at 16:02
  • @GilMoshayof Here is a screenshot with the pixelated emoji display [Imgur](http://i.imgur.com/fvxGbdR.png) – TechAurelian Aug 30 '15 at 16:11
  • @JatinKumar 1. It's not a single Emoji character I want to display, so I cannot hard code it into a string resource. That was just an example in the question, but I will be using code that converts an integer Unicode code to a string. 2. Most Emoji characters are 16-bit Unicode, how can you add it into a string resource? – TechAurelian Aug 30 '15 at 16:33
  • Check out my workaround here: https://stackoverflow.com/a/59698689/1212526 – Tané Tachyon Jan 11 '20 at 21:49

1 Answers1

3

It's an android issue Issue with emoji with 200sp size No way to fix it at the moment, just don't set size more than 199 if you have emoji in TextView

Wackaloon
  • 2,285
  • 1
  • 16
  • 33