Graphics Font External

String path = getExternalCacheDir() + "/myfont.ttf";



//let us copy the font on private storage.
copyFiletoExternalStorage(R.raw.myfont2, "myfont.ttf");

//let us load the font
Typeface myTypeface = Typeface.createFromFile(path);

//let us set the font to text view

 txt2.setTypeface(myTypeface);

}

private void copyFiletoExternalStorage(int resourceId, String resourceName){
        String pathSDCard = getExternalCacheDir() + "/myfont.ttf";//Environment.getExternalStorageDirectory() + "/Android/data/" + resourceName;
        try{
            java.io.InputStream in = getResources().openRawResource(resourceId);
            java.io.FileOutputStream out = null;
            out = new java.io.FileOutputStream(pathSDCard);
            byte[] buff = new byte[1024];
            int read = 0;
            try {
                while ((read = in.read(buff)) > 0) {
                    out.write(buff, 0, read);
                }
            } finally {
                in.close();
                out.close();
            }
        } catch (java.io.FileNotFoundException e) {
            e.printStackTrace();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }

Komentar

Cara pembuatan Apps paling Populer

Create Stopwatch App in Android using Sketchware

How to enable download in webview in Sketchware apps?

TextInputLayout in Sketchware

Create Stopwatch App in Android using Sketchware

How to integrate Admob Ads in Sketchware project using AIDE?

How to find and​ highlight a word in a text field in Sketchware?

Code for implementing Notifications in Sketchware

A Flash Light App in Sketchware

Create a Stopwatch App using Chronometer in Sketchware

Create app to save all passwords, protected using voice key