How to Change the Font of the Text in Android Studio? - android

So, I am making a Game called Fall Down 4 and currently I am just using the built in font (the font that it usually comes with). Now, I want the Title to look more attractive and Good and to do that, i actually downloaded different fonts from Google. I Then created a assests folder and in that folder i copied the font that i installed in my computer (I looked at the different forums on stack overflow). Now my question is how Do i Change the default font to this new downloaded font. Like I just Don't know where to go to change the font of the Text.
I have seen many people ask this question on this fourm but what i want is different FONTS, a FONT that is not BUILT IN, i wannt to USE the FONT I DOWNLOADED and That is what I need help With.
So Please tell me step by step on how to change the font of the text to the font That I have installed in my computer.
The Code:
public class FallDown4TitleScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fall_down_title_screen);
Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "Spac3 tech free promo.ttf");
final Button playbutton = (Button) findViewById(R.id.Playbutton);
final Button custButton = (Button) findViewById(R.id.custButton);
final Button settingButton = (Button) findViewById(R.id.settingButton);
final TextView textView = (TextView) findViewById(R.id.textView);
textView.setTypeface(myTypeFace);
playbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
custButton.setVisibility(View.INVISIBLE);
settingButton.setVisibility(View.INVISIBLE);
textView.setVisibility(View.VISIBLE);
playbutton.setVisibility(View.INVISIBLE);
}
});
}
}

If you are looking to set a custom TrueType font from your asset folder to some textviews or similar views, you could simply do like:
textview.setTypeface(Typeface.createFromFile(getAssets(),"fonts/yourfont.ttf"));
take a look at this discussion if you are looking to change the default font in your app:
Is it possible to set a custom font for entire of application?
However, mobile games generally use bitmap fonts, and draw that on canvas.
Hope that helped!!

Related

Support Gujarati fonts in recycler view in android

I am currently working on an android application which needs Gujarati font support. I have tried the typeface method but all in vain. I tried to find the solution on internet but didn't quiet get the solution.
I am using recycler view in which I need to display the text view using Gujarati fonts.
I kindly request you to help me with this.
Thanx in advance .... :):)
Here is the method i used to add custom gujarati fonts in the ViewHolder method of RecyclerView
public ViewHolder(View v) {
super(v);
mNameTextView = (TextView) v.findViewById(R.id.nameTextView);
Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/guj.ttf");
this.mNameTextView.setTypeface(tf);
this.mNameTextView.setTextColor(Color.DKGRAY);
}
Finally got the Solution. All i needed was the official google NotoSansGujarati font which can be downloaded from the given link.
https://www.google.com/get/noto/
public ViewHolder(View v) {
super(v);
mNameTextView = (TextView) v.findViewById(R.id.nameTextView);
Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/NotoSansGujarati-Bold.ttf");
this.mNameTextView.setTypeface(tf);
this.mNameTextView.setTextColor(Color.DKGRAY);
}
If you're using Android 5.0 (Lollipop), Google has added fonts.
The fonts are called Noto Sans Gujarati and Noto Sans Gujarati UI.
As you're working on an application, that has to be compatible for all the Android Versions, you have to root the particular device for that to work on.
Reference 1
Reference 2

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.

textStyle for Tamil font?

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.

Issue in custom font (RTL labguage)

According to android 2.3 some RTL languages such as Arabic is supported in this new version. However, emulator does not show the fount correctly. In code I have written:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txt = (TextView) findViewById(R.id.myText);
Typeface font = Typeface.createFromAsset(getAssets(), "Larabieb.ttf");
txt.setTypeface(font);
txt.setTextSize(26);
txt.setText("السلام علیک یا حبیبی");
}
but in the output it shows separated characters instead of connected characters.
How can I connect the characters?
As of this date only Samsung's phones running on android support bidi and display of arabic characters. There is nothing wrong with your code. Open the web browser and browse an arabic website you will see the same problem on non-samsung phones.
you can use this tools
Tools.fa("سلام علیکم");
sample image:

import fonts into eclipse to support unicode

how can i import musica fonts into eclipse to support musical unicode? Any workaround?
This is the simple one.
create a folder in the root of your project called assets/fonts/ then paste the TTF font file (in this case Verdana.ttf). Then, if you want to apply that font to, say a TextView, do the following:
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);
Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/Verdana.ttf");
tv.setTypeface(face);
}
}
This example was taken from the ComonsWare book (written by Mark Murphy). You can download the full example from GitHub .

Categories

Resources