textStyle for Tamil font? - android

I'm already working on an Android application that displays RSS feed.
My problem is that this feed has some lines in Tamil(which Android still doesn't support)
I found a font online that displays the text right(without converting to Bamini) but the problem is that textStyle doesn't have any effect on it.
so you know any font that can do the job or any thing i have to do to make textStyling?
thanks in advance

What you need to do is import custom fonts on to the phone before using them.
A good way to do that is to include them in the package - in the APK file
Hence you should be having the font in your project when you build the APK file.
Let me give you an example. Assuming your tamil font's name is Harabara.ttf and you have copied it to /assets/fonts
Use this method (anywhere in your activity)
private void initializeFonts() {
font_harabara = Typeface.createFromAsset(getAssets(), "fonts/Harabara.ttf");
}
and call this API from your onCreate like this
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeFonts();
setContentView(getViewResourceId());
}
Make sure you have declared this class level variable
Typeface font_harabara = null;
Finally, simply use
myTextField.setTypeface(font_harabara);
tada ! tamil font should now start displaying.
nandri vanakkam,
vaidyanathan

There are hundreds of fonts available online. Did you check some TSCII fonts?
I've written some solutions for Tamil and Android issues. Check it out too.

Related

Android - Forecast.io icon label to custom font: weather-icons

I'm currently building a weather app using the forecast.io api.
They provide custom font for Forecast.io, as well as for other apis such as Yahoo. I'm not sure about how to proceed to use their API mapping.
For instance, I receive "partly-cloudy-night" and this should render the icon.
I would welcome advices or clues on how to proceed.
Thanks a lot,
You have to use the ttf file il your android project, and convert the css to xml string ressource.
I did it for Web Hosting hub glyph (a bit like font awesome but many more icons).
See https://github.com/neoteknic/whhg-to-android
I can reuse my convertion script an make a repo with these icons.
Edit :
This is for you :
https://github.com/neoteknic/weather-icons-to-android
To use it (I prefer load only once the typeface and make it available globally) :
public class YourAppName extends Application {
public static Typeface weatherIcons;
#Override
public void onCreate(){
YourAppName.weatherIcons= Typeface.createFromAsset(getApplicationContext().getResources().getAssets(), "fonts/weathericons-regular-webfont.ttf");
super.onCreate();
}
}
Then when you wanna use it :
TextView myicon=(TextView) findViewById(R.id.myicon);
myicon.setTypeface(YourAppName.weatherIcons);
myicon.setText(R.string.wi_day_snow_wind);

Android Studio: Layout Preview gives "native typeface cannot be made"

I'm using a font I found on the internet. In particular, the font that is currently causing a problem is Amaranth (Google Fonts link).
I've looked through these questions:
Native typeface cannot be made
RuntimeException: native typeface cannot be made
native typeface cannot be made, exception
custom font in android studio
All of those questions seem to be dealing with crashes that occur on the device at runtime. My problem is that I get this Exception when trying to use Android Studio's Preview tool to preview my layout.
The text I'm seeing in the "Rendering Problems" pop-up is this:
Exception raised during rendering: native typeface cannot be made
java.lang.RuntimeException: native typeface cannot be made   
at android.graphics.Typeface.<init>(Typeface.java:147)   
at android.graphics.Typeface.createFromAsset(Typeface.java:121)   
at app.SegmentButton.onDraw(SegmentButton.java:79)
The code in SegmentButton is this:
#Override
public void onDraw(Canvas canvas) {
// Other code...
String fontPath = "fonts/Amaranth-Bold.otf";
// The next line is the line that causes the "crash"
Typeface tf = Typeface.createFromAsset(mContext.getAssets(), fontPath);
textPaint.setTypeface(tf);
// Other code...
}
I have checked and ensured the following items:
My assets folder is in 'app/src/main/assets'
My fonts folder is in 'app/src/main/assets/fonts'
The file name is exactly "Amaranth-Bold.otf"
This font works exactly as desired when running my app. I have tested this on an LG Optimus Pro G as well as a Droid X. You can see the results in these images:
LG Optimus G Pro Screen Shot
Droid X Screen Shot
As you can see, the fonts show up as desired in both places. As you can probably also see, the Droid X screen shot shows some layout issues that I need to resolve. I'm trying figure out how to do this at design time using the tools built in to Android Studio. This is merely the first issue I'm tackling. I would hate to have to run the app each time in order to make small tweaks to the layout. This is especially true since these are the only two hardware devices I currently have, and I want to test on a much wider variety of screen sizes (and the emulator is sloooooooooow).
Based on my reading of other questions (and primarily based on the fact that the devices load the font fine at runtime), my current conclusions are:
The font file isn't "broken".
The font location isn't wrong.
The typed-in file name isn't wrong (extension, capitalization, etc.)
What else can I try?
I had the same problem yesterday. Android Studio gives you this tip:
Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
Rewrite your onDraw() method like this:
#Override
public void onDraw(Canvas canvas) {
// Other code...
if(!isInEditMode())changeFont();
// Other code...
}
private void changeFont(){
String fontPath = "fonts/Amaranth-Bold.otf";
Typeface tf = Typeface.createFromAsset(mContext.getAssets(), fontPath);
textPaint.setTypeface(tf);
}

How to display Sinhala Unicode characters in android app

I,m trying to show Sinhala Unicode characters in android app.
when i am using Samsung tabs or phones Unicode is running it on without problem.but it does not work on other phones or tab.cause there is no Sinhala Unicode.How to do this for an example i run this code on Samsung tab successfully.
Toast.makeText(this, "අන්තර්ජාල සම්බන්දතාවය තිබේ ", Toast.LENGTH_SHORT).show();
but other phones or tab does n't work.
You might need to have a Sinhalese font file (say, Sinhalese.ttf) in the directory assets/fonts in the root of your project. You create a dummy text view because it has a method called setTypeface, which sets the font for next code:
import android.graphics.Typeface;
public class FontSampler extends Activity {
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.custom); // a dummy text view
Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/Sinhalese.ttf");
tv.setTypeface(face);
Toast.setView(tv).makeText(this, "අන්තර්ජාල සම්බන්දතාවය තිබේ ", Toast.LENGTH_SHORT).show();
}
}
This way, even if an android phone doesn't have a font installed, then the font embedded in your app will serve. Hope this helps.
If you want to render the Both sinhala and English in same text box then use Iskolapota font file.And do the same as #Nonymous answer says. It works for me.

Typing Urdu/Arabic in TextEdit/TextView in Android

I want to create a database in which i can add and retrieve the Urdu words. for this purpose i installed Inpage 2009 professional and copied its fonts (.ttf) into assets folder but it gave an error i.e
I also installed UrduFonts.exe and copied its font JameelNooriNastaleeq.ttf but it also gave the same error. i need the Urdu font that is compatible to the android , the font that can add and retrieve Urdu to and from the database using android.
this is how i coded foa a Lcd2Mono.ttf and i am having the true experience of that font but i am unsuccessful. here is my piece of code..
private EditText txt,start,urdu;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
urdu=(EditText) findViewById(R.id.urdu);
try
{
urdu.setTypeface(Typeface.createFromAsset(this.getAssets(),"urdu.ttf"));
urdu.setText("ur text");
}
catch(Exception ex)
{
start.setText(ex.toString());
}
i did some with Inpage Fonts and got Exception that Native Font.....
i think JameelNooriNastaleeq.ttf font is very huge, more than 10M (maybe somehow connected to your problem), i recommend to try something much more smaller like: http://www.quran.or.kr/urdu/font/asunaskh.ttf
but still issue with connecting the urdu characters, like in this question:
how to add language support to android
what exception you got?

Bengali unicoded character showing problem

I have created an android application where I want to display unicoded bengali sentences.
For this I have done the following steps.
Step1: I store my bengali font named Siyamrupali.ttf in the Assets folder.
Step2: In main.xml file I took a text view where I display characters.
Step3: In my MainActivity. Java I wrote this...
public class mainAc extends Activity
{
AssetManager arabi_font;
TextView tx;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tx=(TextView)findViewById(R.id.tv);
try
{
String str="\u0986";
tx.setTypeface(Typeface.createFromAsset(getAssets(),"Siyamrupali.ttf"));
tx.setText(str);
}
catch(Exception ex)
{
tx.setText("font cannot load: "+ ex.toString() );
}
}
Then output show আ Which one is correct But When i wrote String str="\u0986\u09AE\u09Bf";
In MainActivity. Java
Then output shows আমই But i should be আমি
What can I do now to solve this problem. Any body give me some advice or link or sample code.
\u0986\u09A\u09BF is not a valid unicode character. I am afraid why you didnot get error. please have a look on the following like
Unicode character of Bengali scripts
Thanks
Android doesn't have full complex text layout support for all of Unicode yet, and Bengali matras are one feature that isn't rendered right. See issue 5925. Sorry!

Categories

Resources