Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font resources for different Languages

I'm trying to use font resource directory and use different fonts in xml files in order to use them in preference. I read this thread but I couldn't solve the problem. I'm using support library v27 and I know it supports font in res instead of asset folder. Whenever I change the language of app it only uses just the font which is located in font-fa-rIR folder. I want application uses different fonts for different type of languages respectively. I have attached an image from res directory of application. Where is my problem? How can I solve it? Thank in advance.

preference_button.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp">

    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/font_1" />

    <TextView
        android:id="@+id/summary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/font_1" />

</LinearLayout>

Font resource directory

Effect of font on English language, as you can see the numbers are still in Farsi which means it uses Farsi font

Effect of font on Farsi language

like image 461
Mohsen Hatami Avatar asked Nov 07 '22 03:11

Mohsen Hatami


1 Answers

May be This Que Helps You

Ref: Chnaging Locale It self

Locale locale2 = new Locale("fr"); 
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(
    config2, getBaseContext().getResources().getDisplayMetrics());

Font From Res

TextView tv_the = (TextView) findViewById(R.id.the);
Typeface face = Typeface.createFromAsset(getAssets(), "font.ttf");
tv_the.setTypeface(face);

For More Info : How to set custom font in .xml file instead of .java file?

like image 68
Ashvin solanki Avatar answered Nov 15 '22 04:11

Ashvin solanki