I want to use Roboto font for All views in my android application ,how can I do that?
Asked
Active
Viewed 1,387 times
1
-
On the answers below, be care of memory leaks when using Typeface createfromasset. Do a search for that problem. Your question has also been covered before. – logray Feb 01 '13 at 16:11
2 Answers
1
Create custom view such as TextView, EditText, etc.. Then you set in the constructors the setTypeface example below:
public class RobotoTextView extends TextView {
public RobotoTextView(Context context) {
super(context);
setTypeface(Typeface
.createFromAsset(context.getAssets(), "fontname.ttf"));
}
}
And then just use this in you're layout, instead of using the standard TextView use your custom class example below:
<packagename.RobotoTextView
style="@style/usecustomstyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yourid"/>

QVDev
- 1,093
- 10
- 17
-
-
See the below xml example you can just use it in any xml layout. Just as you use the normal Android items. just access it with you packagename and class name – QVDev Feb 01 '13 at 16:26
-
-
Yes, just put the font in your'e assets folder and use that. So any font you can use! – QVDev Feb 01 '13 at 16:35
0
use Typeface. Put your font file in assest folder. And then write below code.
Typeface Roboto = Typeface.createFromAsset(getAssets(), "Roboto.ttf");
And then use Roboto font all your TextView
,EditText
..etc
Textview.setTypeface(italic);

MuraliGanesan
- 3,233
- 2
- 16
- 22