Sushil
Sushil

Reputation: 1

How can I make my TextView font as shown in image

I am trying to style my text of STUDENT LOGIN which is shown in the image. But I don't know how can use a different custom font to make my STUDENT LOGIN to look like as shown in the image.

I want Style in that way. How Can I make my S and L shown in image

Student Login Image with customized font

Upvotes: 0

Views: 212

Answers (5)

Vladyslav Matviienko
Vladyslav Matviienko

Reputation: 10881

you can use simple HTML tags in your strings. You can do the following:

textView.setText(Html.fromHtml("<b>S</b>tudent <b>L</b>ogin"));

This way S and L will become bold, while all other chars will be regular.

Upvotes: 0

Ayush
Ayush

Reputation: 173

If you do not want to use spannable you can use this :

String sourceString = "<b>" + id + "</b> " + name; 
mytextview.setText(Html.fromHtml(sourceString));

Upvotes: 0

Ronak Doshi
Ronak Doshi

Reputation: 155

First of all set your font to the TextView

TextView textView = (TextView) findViewById(R.id.textview);
Typeface myTypeface = Typeface.createFromAsset(getContext().getAssets(), "font/myFont.ttf");
textView.setTypeface(myTypeface);

Now, You can achieve different size of S and T using SpannableString

String s = "STUDENT LOGIN";
SpannableString ss = new SpannableString(s);
ss.setSpan(new RelativeSizeSpan(2f), 0, 1, 0);       // Set Size
ss.setSpan(new RelativeSizeSpan(2f), 8, 9, 0);       // Set Size
textView.setText(ss);

Here replace 2f according to size you want.

0 is starting index of S and 1 is ending index.

8 is starting index of L and 9 is ending index.

Upvotes: 2

SANAT
SANAT

Reputation: 9277

If you don't want to use default font and want to use different font without hassle, just use this library. You can apply custom font to whole app or particular TextView.

Example for specific TextView :

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    fontPath="fonts/Roboto-Bold.ttf"/>

Follow the instruction from read me file and you will get what you want.

Upvotes: 0

Sasi Kumar
Sasi Kumar

Reputation: 13358

Find font family then Get it font yourfont.ttf file from internet and paste into assets folder in android.

Then apply your Textview

Typeface customTypeface = Typeface.createFromAsset(getContext().getAssets(), "font/custum_font.ttf");
myTextView.setTypeface(customTypeface);

Upvotes: 1

Related Questions