我知道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
更新
我的字体文件目录:E:\AndroidProjects\ReadNews\ReadNews\src\main\assets\fonts\
更新结束
我的代码:
@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);
}
错误:
06-27 07:40:37.985 4206-4206/com.mmd2009.readnews E/AndroidRuntime﹕ 致命错误:主进程 进程:com.mmd2009.readnews,PID:4206 java.lang.RuntimeException: 无法创建原生字体 at android.graphics.Typeface.(Typeface.java:175) at android.graphics.Typeface.createFromAsset(Typeface.java:149) at com.mmd2009.readnews.MainActivity$ReadNewsAsyncTask.onPreExecute(MainActivity.java:216) at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587) at android.os.AsyncTask.execute(AsyncTask.java:535) at com.mmd2009.readnews.MainActivity$1.onClick(MainActivity.java:70) at android.view.View.performClick(View.java:4438) at android.view.View$PerformClick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
我的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>