Display all Unicode chars in TextView
Is there any way to show all Un开发者_如何学JAVAicode 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?
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
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
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:
精彩评论