Roboto Font in Android App

Hi, I am writing an Android application. And I want the roboto font in it regardless of the phone version. Is there any way to do this?

Thanks, Rahim.

+5
source share
4 answers

Yes, why not, you can get the Roboto font:

Android ICS Printing House

Suppose you want to change the font of the text view:

   Typeface tf = Typeface.createFromAsset(getAssets(),
            "fonts/Roboto-Black.ttf");
    TextView tv = (TextView) findViewById(R.id.FontTextView);
    tv.setTypeface(tf);
+18
source

Try this link http://www.barebonescoder.com/2010/05/android-development-using-custom-fonts/

Set the typeface property of the control you are targeting to serif ... and for the font file that I recommend using TTF, it worked for me in the past

Also try these links

http://techdroid.kbeanie.com/2011/04/using-custom-fonts-on-android.html

Android -

+1

XML, , Eclipse ADT XML-. , .ttf .

textview:

public class TypefacedTextView extends TextView
{
 public TypefacedTextView(Context context, AttributeSet attrs)
 {
  super(context, attrs);

   // Typeface.createFromAsset doesn't work in the layout editor. Skipping ...
   if (isInEditMode())
   {
    return;
   }

   TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
   String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);
   styledAttrs.recycle();

   if (fontName != null)
    {
     Typeface typeface = Typeface.createFromAsset(context.getAssets(), fontName);
     setTypeface(typeface);
    }
   }
  }

, TypefacedTextView XML-, XML Android XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:your_namespace="http://schemas.android.com/apk/res/com.example.app"
... />

And use your TypefacedTextView as plain text in XML, but with your own tag, remembering to set the font:

<com.example.app.TypefacedTextView
  android:id="@+id/list_item_entry_title"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:gravity="center_vertical"
  android:minHeight="48dp"
  android:textColor="#FF787878"
  your_namespace:typeface="Roboto-Regular.ttf" />

See my blog for more information: http://polwarthlimited.com/2013/05/android-typefaces-including-a-custom-font/

+1
source

You can apply special styles in android that allow you to change the font, etc. Check out this link to the Android developer site.  Styles and Themes

-2
source

All Articles