Issue in the Assets folder - android

I had an issue where a font didnt work and it gave me a FC. So I put the font file into the sdcard, and used CreateFromFile in the typeface and the font worked!
Here is the code I used for the Assets folder:
holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf"));
But I changed the code to this and it worked:
holder.tv_SuraName = (TextView)convertView.findViewById(R.id.Start_Name);
Typeface Font = Typeface.createFromFile(new File(Environment.getExternalStorageDirectory()+"/asd.ttf"));
Does this mean I have a problem in the Assets folder? How can I fix this? Thanks

see this
Typeface font0 = Typeface.createFromAsset(getAssets(),"fonts/AmericanDream.ttf");
tv1.setTypeface(font0);
here fonts (folder in assets) folder containing AmericanDream.ttf file inside.
like:assets-->fonts-->AmericanDream.ttf
i hope this will help u.

AssetManager assetManager1 = getApplicationContext().getAssets();
Typeface tf1 = Typeface.createFromAsset(assetManager1, "James_Fajardo.ttf");
and used in textview like
urTextView.setTypeface(tf1, Typeface.BOLD);
hope useful for u.

Related

how to use font family like professional in android studio

Is, any professional font family available on android. If it is not available, then how to use professional fonts in android. Thanks in advance
You can flow this step:
1.Go to the (project folder)
2.Then app>src>main
3.Create folder 'assets>fonts' into the main folder.
4.Put your 'abc.ttf' into the fonts folder.
AssetManager am = context.getApplicationContext().getAssets();
typeface = Typeface.createFromAsset(am,
String.format(Locale.US, "fonts/%s", "abc.ttf"));
setTypeface(typeface);
To add a font to your App, place the font file in asset folder and use the following code to set it to text view...
TextView textView = (TextView) findViewById(R.id.textView);
Typeface typeFace = Typeface.createFromAsset(getAssets(),
"fonts/digital.ttf");
textView.setTypeface(typeFace);
to get the fonts follow this link.
https://fonts.google.com
These are the google recommended fonts.

Assets folder in Android Studio?

Im trying to use a custom font, and I've read that I suppose to place the fonts in assets/fonts. I'm using Android Studio and it doesn't seem like I have a assets folder. So I created one. But my app crashes when I place the assets folder in src/main. Im using this code to load my fonts.
Typeface fontRegular = Typeface.createFromAsset(getAssets(), "fonts/DroidSans.ttf");
Typeface fontBold = Typeface.createFromAsset(getAssets(), "fonts/DroidSans-Bold.ttf");
myDeviceModelTxt.setTypeface(fontRegular);
What am I doing wrong?
I am not sure if there has been any bug fixes since this was asked, but I am using the current structure for a project in Android Studio 0.5.2:
root-module
|--.idea
|--app
|----build
|----src
|------main
|--------assets
|----------SomeFont.ttc
|----------AnotherFont.otf
|--------java
|----------source code here
|--------res
|------AndroidManifest.xml
|----build.gradle
And then obtain it by calling
Typeface.createFromAsset(mContext.getResources().getAssets(), "SomeFont.ttc");
Word of caution though, there is a bug (https://code.google.com/p/android/issues/detail?id=9904) that prevents typefaces from being garbage collected properly. Use a singleton!
Create Assets folder Right click on app->>new->>Folder->>AssetsFolder like below image
Put your font inside this folder by just copy and paste. and use below code for example..
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "YourFontName.ttf");
setTypeface(tf);
Simply follow this path:
File > New > folder > assets Folder
Here App must be selected before creating folder.
For more information see this answer
The assets folder should be placed under the root of the project.
See here for more examples.

How to modify font without using assets

AssetManager mgr=getAssets();
Typeface tf=Typeface.createFromAsset(mgr, "fonts/cube.ttf");
textView.setTypeface(tf);
The method above can modify font of the TextView, but I do not want to do it like this. My idea: The user can download the font on the internet and store it in the sd-card. Then the user can apply the font they just downloaded to the widget. I feel this method can reduce the size of the project. Any suggestions?
1.) Download "font.ttf" (Replace with your ttf file name) File to external storage through the internet.
2.) Do this.
Typeface typeface = Typeface.createFromFile(
new File(Environment.getExternalStorageDirectory(), "font.ttf"));
textView.setTypeface(tf);

How can I set chosen font in textview

I have a question. How Can I set font for example: Harrington in textview. I use:
Typeface type = Typeface.createFromFile("C:/Fonts/Kokila.ttf");
gameResult.setTypeface(type);
gameResult = (TextView) findViewById(R.id.textViewResult);
but this solution is not working. Any ideas?
first place your font in assets folder then like:
gameResult = (TextView) findViewById(R.id.textViewResult);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf");
gameResult.setTypeface(type);
You are trying to access the font from your PC! Your phone does not have access to the 'C:/' drive of your PC, and therefore cannot load the font. You need to place the Font into the Assets folder of your application, and then read it from there.
You can read a file from the Assets folder using
context.getAssets().open(fileName);

How to set gujarati for textview in the android application?

I want to make a application in which i needs to show the textview in gujarati language.
I tried with
Typeface tf = Typeface.createFromAsset(getAssets(), "G-SARAL1.TTF");
text.setTypeFace(tf);
but this is not working, I set the gujarati text in string.xml file and then i set that string in the textview, but when i run the application, it display square boxs instead of gujarati character,
can anyone help me , how can i implement this task.
As gujarati and hindi languages are not supported by Android, you can still give that support to your Application.
For Gujarati copy the C:\WINDOWS\Fonts\Shruti.TTF file to your asset folder. Then use the following code.
TextView text_view = new TextView(this);
Typeface font = Typeface.createFromAsset(getAssets(), "Shruti.TTF");
text_view.setTypeface(font);
text_view.setText("ગુજરાતી");
Shruti.TTF file is for Gujarati font. Similarly you can add support for hindi file.
Try this code this will work
TextView mtxt = (TextView) findViewById(R.id.action_settings);
Typeface face1 = Typeface.createFromAsset(getAssets(),
"Lohit-Gujarati.ttf");
mtxt.setTypeface(face1);
mtxt.setText("પૂર્વ વડાપ્રધાન રાજીવ ગાંધીની હત્યા કરનારા 3 આરોપીઓની ફાંસીની સજા સુપ્રિમ કોર્ટે ઉમ્રકેદમાં ફેરવી નાંખી છે.આમ રાજીવગાંધીના" +
"3 હત્યારાઓને હવે ફાંસીની સજા નહી થાય.સુપ્રીમ કોર્ટમાં 3 જજોની બેન્ચે આજે આ ચુકાદો આ");
You can download the Montserrat fonts, this font is use for both language English and Gujarati. If you do not want to download the saperate fonts than can use this. You can make base text and can create method like below and use the fonts. One more thing you have to pass the
fun setFonts(context: Context, fontName: String) {
val typeface = Typeface.createFromAsset(context.assets, fontName)
setTypeface(typeface)
}
To create localized string file you can also use Translations Editor.
I checked out all the given solutions but no one solved my prob
so I did some more and more google and found out that, you need to create assets folder first
and then paste all the fonts file which you required in your application
here is a little guide for how we can add assets folder in our project
Step 1 : Navigate to the top left side of an android studio where you got menu like this and just change the option from the dropdown to Packages
Step 2 : now you will see parent as app and now just right click on the app and click new and then Folder and then Assets Folder
this is how you can add Assets Folder.
once you add Assets Folder then simply paste your ttf files into that Assets folder.
and follow my code for reference
TextView text_view = (TextView) findViewById(R.id.txtMsg);
//TextView text_view = new TextView(this);
Typeface faceShruti = Typeface.createFromAsset(getAssets(),
"shruti.ttf");
text_view.setTypeface(faceShruti);
text_view.setText("In Gujarati\n" + "સ્વાગત");

Categories

Resources