Reputation: 105
I am developing a custom soft keyboard for Android. The problem is that I do not want to just set the text of the buttons in my keyboard to my custom font. I also want the output text to be in my custom font which is DroidSansFallback.ttf
. Basically, I want my users to be able to type with my keyboard in this custom font. Therefor, the user should be able to use the keyboard to type in the custom font across all applications. I have found one application called Multiling that does the same thing.
I have tried the following steps as :
1.Overriden the onDraw()
,
2.setTypeface
in paint , 3.paint.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"mycustomfont.ttf"))
,
4.attrs.xml is duly added(but no typeface reference is mentioned there)
Upvotes: 2
Views: 4071
Reputation: 7071
To embed a custom font into your app, you need to create an "assets/fonts" folder and copy your TTF file there.
If you have sub class of TextView then you can directly call this piece of code from its costructor,
Typeface font = Typeface.createFromAsset(this.getContext().getAssets(), "fonts/mycustomfont.ttf");
setTypeface(font);
Otherwise, If you want to use TTF without making sub-class then you can follow these steps in Activity class.
Typeface font = Typeface.createFromAsset(this.getContext().getAssets(), "fonts/mycustomfont.ttf");
TextView tv = (TextView)findViewById(res);
tv.setTypeface(font);
For more details follow this link.
Upvotes: 3