Search code examples
androidandroid-stylesandroid-appcompatandroid-fonts

Android FontFamily support for AppCompat


Does anyone know how to overcome the issue of font family support for the AppCompat theme?

I used AppCompat v7 Library in Android that handles well on ActionBar issues but the attribute mentioned below is not available in the android values/style.xml default folder.

Which is why i am unable to customize Edittext control.

<item name="android:fontFamily">sans-serif</item>

What would be the alternative way to use the custom font?


Solution

  • I also use custom font in my application.

    To custom the title of action bar you need to use the next code.

    private void changeSizeTitle() {
    
        fontTitle = Typeface.createFromAsset(context.getAssets(),
                "fonts/helvetical.ttf");// font in the file assets/fonts
        int titleId = getResources().getIdentifier("action_bar_title", "id",
                "android");
        TextView yourTextView = (TextView) findViewById(titleId);
        yourTextView.setTypeface(fontTitle);
        yourTextView.setTextSize(20);
    }
    

    be careful when you restart the activity, you need to call again that method.