Below is my code where I am using typeface correctly to change the font for the punjabi but it is still showing incorrect text on Galaxy S2 and punctuations on phones other than Samsung. Not sure how can I fix this
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Typeface tf = Typeface.createFromAsset(getAssets(),
"fonts/ANMOL_L.TTF");
TextView txt = (TextView) findViewById(R.id.text);
txt.setTextSize(40);
txt.setTypeface(tf);
txt.setText("ੴ ਸਤਿ ਨਾਮੁ ਕਰਤਾ ਪੁਰਖੁ ਨਿਰਭਉ ਨਿਰਵੈਰੁ ਅਕਾਲ ਮੂਰਤਿ ਅਜੂਨੀ ਸੈਭੰ ਗੁਰ ਪ੍ਰਸਾਦਿ ॥");
}
}
Try txt.setText("Testing"); And you will notice you will see Punjabi text. This is because the font you have chosen is not a Unicode compatible font. It overrides ASCII codes. Choose another font file.
I have tested AnmolUni.ttf and AmbarSlim.ttf files from http://www.gurbanifiles.org/unicode/ and they work.
Related
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!!
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
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.
i have used many punjabi fonts as like bulara_f.ttf , anmollipi , Akaash and many more but every time prolem with one word of punjabi "sihari"
Sihari : Sihari is equivalent to i in pin or thin. Hence forth in this module we will denote sihari vowel with /i/.
in my application only this one word is not shown properly as like in following snapshot... please help...
EDIT
i am using this method
Typeface myfont;
myfont=Typeface.createFromAsset(getAssets(),"font.ttf");
TextView textview = (TextView)findViewById(R.id.TextView01);
//textview.setText("punjabi Text");
textview.setTypeface(myfont);
}
Use bulara_5.ttf and run the code on device it will show correct punjabi words
mTvAbout = (TextView) findViewById(R.id.tv_about);
font = Typeface.createFromAsset(this.getAssets(), "bulara_5.ttf");
mTvAbout.setTypeface(font);
mTvAbout.setText(" ਜਾਣਕਾਰੀ");
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: