custom font in Android Studio -
how create custom fonts in android studio ? im trying use custom font, , i've read suppose place fonts in assets/fonts. have searched long , hard found nothing helped yet. wrong? not know do. wrote details below. i've tried , did not succeed. i'm using android studio , doesn't seem have assets folder. created one. app crashes when place assets folder in /main/assets. im using code load fonts.
i know . structure project in android studio 0.5.2:
root-module |--.idea |--app |----build |----src |------main |--------assets |----------fonts/somefont.ttc |----------fonts/anotherfont.otf |--------java |----------source code here |--------res |------androidmanifest.xml |----build.gradle
update
my fonte file dir : e:\androidprojects\readnews\readnews\src\main\assets\fonts\
end update
my code :
@override protected void onpreexecute() { textview titletextview = (textview) _dialog.findviewbyid(r.id.title_news_textview); textview messagetextview = (textview) _dialog.findviewbyid(r.id.message_textview); string fontpath = "fonts/tahoma.ttf"; typeface tf = typeface.createfromasset(mainactivity.this.getresources().getassets(), fontpath); titletextview.settypeface(tf); messagetextview.settypeface(tf); }
error :
06-27 07:40:37.985 4206-4206/com.mmd2009.readnews e/androidruntime﹕ fatal exception: main process: com.mmd2009.readnews, pid: 4206 java.lang.runtimeexception: native typeface cannot made @ android.graphics.typeface.(typeface.java:175) @ android.graphics.typeface.createfromasset(typeface.java:149) @ com.mmd2009.readnews.mainactivity$readnewsasynctask.onpreexecute(mainactivity.java:216) @ android.os.asynctask.executeonexecutor(asynctask.java:587) @ android.os.asynctask.execute(asynctask.java:535) @ com.mmd2009.readnews.mainactivity$1.onclick(mainactivity.java:70) @ android.view.view.performclick(view.java:4438) @ android.view.view$performclick.run(view.java:18422) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5017) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) @ dalvik.system.nativestart.main(native method)
my readnews-readnews.iml :
<facet type="android" name="android"> <configuration> <option name="selected_build_variant" value="debug" /> <option name="assemble_task_name" value="assembledebug" /> <option name="compile_java_task_name" value="compiledebugjava" /> <option name="assemble_test_task_name" value="assembledebugtest" /> <option name="source_gen_task_name" value="generatedebugsources" /> <option name="allow_user_configuration" value="false" /> <option name="manifest_file_relative_path" value="/src/main/androidmanifest.xml" /> <option name="res_folder_relative_path" value="/src/main/res" /> <option name="res_folders_relative_path" value="file://$module_dir$/src/main/res" /> <option name="assets_folder_relative_path" value="/src/main/assets" /> </configuration> </facet>
your font path incorrect. have no font
folder. change font path "tahoma.ttf"
, or create folder inside of asset folder.
edit
this appears bug happens android os on occasion. check out link, appears has been addressed already. "native typeface cannot made" people
Comments
Post a Comment