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

TextInputLayout in Sketchware

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

A Flash Light App in Sketchware

How to enable download in webview in Sketchware apps?

Intent - Open File By Type

Code for implementing Notifications in Sketchware

How to share an image from Drawable folder?

ActionBar back button

Animation Transtition Animation