Display all Unicode chars in TextView

2020-01-25 07:38发布

Is there any way to show all Unicode chars in my TextView, on my phone?

I have tried special characters like '\u0279' and I get something like box (default char). Is this based on l10n and i18n settings?

3条回答
何必那么认真
2楼-- · 2020-01-25 07:51

This usually happens because of the font used, the default one does not support/have implemented all unicode chars, you need to use a full featured font like DejaVuSans.ttf

@sakthi shows a sample that should work without problem, check if your android version supports it

查看更多
Rolldiameter
3楼-- · 2020-01-25 07:53

Try this code:

String str = "\u00F6";

System.out.println("new value-" + str);

You will get:

new value-ö

Here is a sample android project that i created to check the feature:

Java file:

package com.testd;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String str = "\u00F6";

        TextView tv = (TextView) findViewById(R.id.a);
        tv.setText("sajklasdklfjasdf " + str );
    }
}

XML File:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:id="@+id/a" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />
</LinearLayout>

Screen Shot:

enter image description here

查看更多
女痞
4楼-- · 2020-01-25 07:58
tv=(TextView)findViewById(R.id.textView1);
Typeface font= Typeface.createFromAsset(getAssets(), "TAU_BHON.TTF");
tv.setTypeface(font); 

Place the font that will support your language in the assets folder.In this case i have used TAU_BHON.TTF

查看更多
登录 后发表回答