I want to use custom font in my application and i did everything in the right way, but when i build the project and run it it's force stop
because it can't found assets
folder!
That's the code from MainActivity
:
tv = (TextView) findViewById(R.id.wlcText);
tf = Typeface.createFromAsset(getAssets(), "en_font.ttf");
tv.setTypeface(tf);
this is the exception trace:
Caused by: java.lang.RuntimeException: Font asset not found en_font.ttf
at android.graphics.Typeface.createFromAsset(Typeface.java:198)
I have assets
folder in the right path like that image
Also i tried to browse my apk after compilation and i didn't found the assets folder in it like that image!
That's means Android studio can't see the folders in the project structure!
P.S. i tried a lot of questions here and nothing worked with me!
EDIT
That's the build.gradle
with sourceSets:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.mEmoZz.qrgen"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
assets.srcDirs = ['assets']
}
}
}