Comment créer des polices personnalisées dans le studio android? Im essayant d'utiliser une police personnalisée, et j'ai lu que je suppose que placer les polices dans les actifs/polices. J'ai cherché longtemps et dur mais n'ai rien trouvé qui m'aide encore. Où je me trompe? Je ne sais vraiment pas quoi faire. J'ai écrit tous les détails ci-dessous. J'ai essayé et n'ai pas réussi. J'utilise Android Studio et il ne semble pas que je possède un dossier actif. Alors j'en ai créé un. Mais mon application se bloque lorsque je place le dossier des ressources dans/main/assets. Im en utilisant ce code pour charger mes polices.police personnalisée dans Android Studio
Je le sais. structure pour un projet dans Android 0.5.2 studio:
root-module
|--.idea
|--app
|----build
|----src
|------main
|--------assets
|----------fonts/SomeFont.ttc
|----------fonts/AnotherFont.otf
|--------java
|----------source code here
|--------res
|------AndroidManifest.xml
|----build.gradle
Mise à jour
mon fichier dir Fonte: E: \ AndroidProjects \ ReadNews \ ReadNews \ src \ atouts \ \ fonts \
Mise à jour de fin
mon 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);
}
erreur:
06-27 07: 40: 37,985 4206-4206/com.mmd2009.readnews E/AndroidRuntime: EXCEPTION FATAL: principal Process: com.mmd2009.readnews, PID: 4206 java.lang.RuntimeException: caractères natif ne peut pas être à android.graphics.Typeface (Typeface.java:175) à android.graphics.Typeface.createFromAsset (Typeface.java:149) à. com.mmd2009.readnews.MainActivity $ ReadNewsAs yncTask.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) at android.os .Handler.handleCallback (Handler.java:733) à android.os.Handler.dispatchMessage (Handler.java:95) à android.os.Looper.loop (Looper.java:136) at android.app.ActivityThread .main (ActivityThread.java:5017) à l'adresse java.lang.reflect.Method.invokeNative (méthode native) at 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)
mon 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>
J'ai un dossier de police. La structure ci-dessus était juste un exemple. –
Eh bien, ça craint. – user3331142