问题
I am working in android. I am designing an application which shows Hindi words in text view.
I am using this code.
String str="दिव्या";
TextView txtview_name=(TextView)findViewById(R.id.textViewmyView);
final Typeface customF = Typeface.createFromAsset(this.getAssets(), "Hindi-SARAL1.TTF");
txtview_name.setTypeface(customF);
txtview_name.setText(str);
I used font in my resourses like DroidHindi.ttf, DroidSansFallback.ttf etc. this is showing some words correctly like as समर, राजा etc , but this does not show correctly words like as दिव्या So please suggest me what .ttf i should use so each word of Hindi show correctly.
回答1:
@Pushpendra I was having same problem with my testing device (HTC phone). But i tried same app on samsung android phone it works properly on it. So i think you should try your app on different device May be this will help you.
回答2:
Instead of .ttf file, use .otf file.
回答3:
you can use Unicode instead of direct value...
String str="&# 2367;&# 2342;&# 2357;&# 2381;&# 2351;&# 2366;";
continious no gap.
TextView txtview_name=(TextView)findViewById(R.id.textViewmyView);
final Typeface customF = Typeface.createFromAsset(this.getAssets(), "Hindi-SARAL1.TTF");
txtview_name.setText(Html.fromHtml(""+str));
txtview_name.setTypeface(customF);
and you can also convert world to unicode via this site...http://mylanguages.org/converter.php
but in case of दि use 1st unicode of इ then 2nd द ..b/c till android 4.0 not support proper Hindi unicode..&# 2342;
is unicode of द.
来源:https://stackoverflow.com/questions/10329510/android-unable-to-show-correct-hindi-words