0

I want to use Bungee inline font style in my android xml code

  <RelativeLayout 
        android:id="@+id/sound_setting_layout"
        android:layout_width="500dip"
        android:layout_height="350dip"
        android:layout_marginTop="65dip"
        android:layout_marginLeft="780dip"
        android:layout_alignParentTop="true"
        android:padding="10dip"
        android:gravity="center"
        android:visibility="gone"
        android:background="@drawable/volume_layout"
        > 
<TextView
    android:layout_width="450dip"
    android:layout_height="50dip" 
    android:gravity="center_horizontal"
    android:layout_alignParentTop="true"
    android:text="Volume Control"
    android:textStyle="bold"
    android:textColor="#ffffff"
    android:textSize="30dip"        
    />

I tried a lot but i could not find font style Bungee in android.

Mhandroid
  • 219
  • 3
  • 13

3 Answers3

1

load your font file to assets folder then in your activities onCreate , use the following methods

Typeface face = Typeface.createFromAsset(YOUR_ACTIVITY.this.getAssets(),"fonts/YOUR_FONT_FILE_NAME.otf");
your_text_view.setTypeface(face);
Ak9637
  • 990
  • 6
  • 12
1

We don't have default bungee font style in android so if you wanna use it download bungee font .ttf file and create a folder in assets named fonts and paste your downloaded font (.ttf) there Here you can download Bungee font:https://djr.com/bungee/ In your code just do this

 // Font path insted of bungee.ttf replace your .ttf file
    String fontPath = "fonts/bungee.ttf";

    // text view label which you want to apply Bungee font
    TextView txtGhost = (TextView) findViewById(R.id.androidSample);

    // here loading Font Face
    Typeface tf = Typeface.createFromAsset(getAssets(), fontPath);

    // Applying font
    txtGhost.setTypeface(tf);
Rajakumar
  • 907
  • 1
  • 7
  • 17
0

If you're going to use custom fonts throughout your whole application, on multiple TextViews for example, it's bettter to use a Singleton pattern because re-instantiating the fonts over and over will slow down your application.

Try this class and replace the font path with your own custom fonts, make sure you have your custom fonts inside "assets" folder inside "main"

public class ProximaTypeface {
    public static ProximaTypeface instance = new ProximaTypeface();

    public ProximaTypeface() {
    }

    public Typeface regularTypeFace = null;
    public Typeface semiBoldTypeFace = null;

    public static ProximaTypeface getInstance() {
        return instance;
    }

    public void getRegularTypeface(Context context, TextView textView) {
        if (regularTypeFace == null) {
            regularTypeFace = Typeface.createFromAsset(context.getResources().getAssets(), "fonts/proxima_nova_regular.otf");
        }
        textView.setTypeface(regularTypeFace);
    }

    public void getSemiBoldTypeface(Context context, TextView textView) {
        if (semiBoldTypeFace == null) {
            semiBoldTypeFace = Typeface.createFromAsset(context.getResources().getAssets(), "fonts/proxima_nova.otf");
        }
        textView.setTypeface(semiBoldTypeFace);
    }

}

Then in your Activity:

   ProximaTypeface proximaTypeface = new ProximaTypeface();

   TextView myTextView = (TextView) findViewById(R.id.textView);

   proximaTypeface.getRegularTypeface(context,myTextView);
Nour
  • 99
  • 4
  • does this solution behave properly in android 5.1 below ??? since its using reflection – Ak9637 Dec 01 '16 at 08:17
  • I have tested it in apps targeting a minSdkVersion 17 (Android 4.2 Jelly Bean) – Nour Dec 01 '16 at 09:03
  • ok,can we some how use this to set the font of the app itself @Nour – Ak9637 Dec 01 '16 at 09:18
  • You'll have to do some research on that and choose a solution that suits you best, but you may start with this answer http://stackoverflow.com/questions/2711858/is-it-possible-to-set-a-custom-font-for-entire-of-application/16883281#16883281 – Nour Dec 01 '16 at 10:27
  • the link u have mentioned ,the solution fails for below 5.1 – Ak9637 Dec 01 '16 at 11:27