Is it possible to use a custom font in android which is stored in the SD card? What I've seen so far indicates the font file must be in the assets folder. Please tell me I'm wrong.
Typeface.createFromFile() takes a String path or File.
Typeface typeface = Typeface.createFromFile(
new File(Environment.getExternalStorageDirectory(), "font.ttf"));
I have not tried it myself but the recipe states you might be able to do it by using the
Typeface.createFromFile(String path)
http://androidcookbook.com/Recipe.seam;jsessionid=A2DD7A11C804B7C7646DCA883AA452FC?recipeId=1141
Related
Can we set typeface at run time and .ttf file are coming from server means ttf file come from server and we have to set our font according that
Yes its possible. You can download the ttf file into external storage and create TypeFace from that file.
Typeface tf = Typeface.createFromFile(file);
here file should be the ttf file from server.
Yes its possible To set Custom font(s) from server.
Download font from server
Save to SD card
Use Typeface.createFromFile(String path)
textView.setTypeface(yourTypeface);
Code
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromFile(new File(Environment.getExternalStorageDirectory(), "font.ttf"));
tv.setTypeface(face);
I wanna include a text file to my project in smartface appstudio. I put it where? In resources folder or assets? FileStream could not read it in resources (as a drawable item). Any idea?
var txtFile = new SMF.IO.FileStream(SMF.IO.applicationResources, "words.txt", SMF.IO.StreamType.read);
txtFile.readToEnd();
It is not implemented in current release of Smartface App Studio. Also I have tried it before. It is Phase 2 for File Operations.
You can download your static text file from the internet and can save it to the local storage. And read it from there. I can just suggest you this idea. Check some helpful links below.
http://developer.smartface.io/hc/en-us/articles/203177557-File-Operations
http://developer.smartface.io/hc/en-us/articles/202153536-File-Download-Upload
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);
I need to access myfile.txt file using FileReader in Android , please suggest me where to add the text file in Eclipse. I tried it adding it in Resource and Asset but I am getting File not found issue.
FileReader fr = new FileReader("myfile.txt");
Even
File ff = new File("myfile.txt");
File Supports only the below listed parameters
FileReader Supports only the below listed parameters
Note: I want solution for this issue , only with FileReader or File
The directory would be /res/raw/ this is where you put all your extra resources.
you can refer to it using getResources().openRawResource(resourceName)
and check here Android how to get access to raw resources that i put in res folder?
EDIT:
how can i edit the text files in assets folder in android
in short
the easiest way would be to copy the file to external directory then do your stuff there
link is here
Android: How to create a directory on the SD Card and copy files from /res/raw to it?
One thing to mention - prior to 2.3 the file size in the assets cannot exceed 1MB.
hope it helps abit
That's how I obtain my file from the SD card, perhaps this can be some use to you.
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File options = new File(getAppDirectory(), "portal.xml");
}
The getAppDirectory method used in the bit of code looks like this :
private String getAppDirectory() {
return new String(Environment.getExternalStorageDirectory().toString()
+ "/foldername/foldername/");
}
After this bit of code I also make sure the file exists and what not before I attempt to read from it.
I need to get Absolute path to Folder in Assets.
Some like this for sd-card:
final String sdDir = Environment.getExternalStorageDirectory() + "Files";
What i do incorrect?
First I try to get path (in green ractangle) this way but I alwase get "False".
Then I comment this block and try to get path from getAssets().list();
But I get 3 folders witch I see first time.
I want to make massive like this "green" but I need to use files from assets:
Look the image
Help me to get absolute path to my Files folder.
I'm not exactly sure what you're trying to do, so I'll try to cover the bases, and maybe this will help.
If you are just trying to get a list of what's in your assets, then
use getAssets().list("Files"). (You have to use the subdirectory,
because of this).
If you are trying to get an absolute path to your assets directory
(or any subdirectory), you can't. Whatever is in the assets directory
is in the APK. It's not in external storage like on an SD card.
If you are trying to open up files in the assets directory, use
AssetManager.open(filename) to get the InputStream. Here,
filename should be the relative path from the assets directory.
EDIT
I'm not sure what you mean by "massive", but if you want to load the file black.png from assets instead of the SD card, then write this:
// must be called from Activity method, such as onCreate()
AssetManager assetMgr = this.getAssets();
mColors = new Bitmap[] {
BitmapFactory.decodeStream(assetMgr.open("black.png"));
// and the rest
};
Assets are stored in the APK file so there are no absolute path than your application can use. But, I would suggest to take a look at file:///android_asset. It might fits your needs. Here is a good example on how to display an Asset in a WebView.