Tuesday 12 February 2013

Change Font type, Style, Size and Color in TextView

Changing the Font type, Style, Size in Textview can be done via both xml and Java code..
Here i will show both methods.




main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ChangeTextViewPropertity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="24dp"
        android:layout_marginTop="38dp"
        android:text="Text From XML"
        android:textSize="40dp"
        android:textStyle="bold"
        android:typeface="serif"
        android:textColor="#0000CD"
        
         />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="158dp"
        android:text="TextView" />

</RelativeLayout>


ChangeTextViewPropertity.java:
package com.example.font;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.Menu;
import android.widget.TextView;

public class ChangeTextViewPropertity extends Activity {
 TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv=(TextView)findViewById(R.id.textView2);
        tv.setText("Text From Java Code");
        tv.setTypeface(Typeface.SANS_SERIF);
        tv.setTextSize(50);
        tv.setTextColor(Color.RED);
               
    }   
}




Thanks for Visiting
 -- 
Regards with

R. Partha Sarathy

5 comments:

  1. Your blog has given me that thing which I never expect to get from all over the websites. Nice post guys!

    Web Developers Melbourne

    ReplyDelete
  2. Dafont.com is a site where you can download a ton of free fonts. You can search for a specific typeface, or search by the type of lettering you want, whether it’s serif or sans serif, hand lettered or grunge style. You can also put in your own phrase to see how it looks in a particular font. A lot of these fonts are very decorative and many are handdrawn, so it’s not always the best place to search for body text fonts. Each selection also tells you whether your download is free for personal or commercial use. The download is easy – you get a zip file with the font file inside. Unzip, install, and you’re ready to go.

    ReplyDelete
  3. Dafont.com is a site where you can download a ton of free fonts. You can search for a specific typeface, or search by the type of lettering you want, whether it’s serif or sans serif, hand lettered or grunge style. You can also put in your own phrase to see how it looks in a particular font. A lot of these fonts are very decorative and many are handdrawn, so it’s not always the best place to search for body text fonts. Each selection also tells you whether your download is free for personal or commercial use. The download is easy – you get a zip file with the font file inside. Unzip, install, and you’re ready to go.

    ReplyDelete
  4. Dafont.com is a site where you can download a ton of free fonts. You can search for a specific typeface, or search by the type of lettering you want, whether it’s serif or sans serif, hand lettered or grunge style. You can also put in your own phrase to see how it looks in a particular font. A lot of these fonts are very decorative and many are handdrawn, so it’s not always the best place to search for body text fonts. Each selection also tells you whether your download is free for personal or commercial use. The download is easy – you get a zip file with the font file inside. Unzip, install, and you’re ready to go.

    ReplyDelete
  5. The process of promoting your brand is very difficult and it requires a lot of time as well. I was in search of good strategies that need less investment and still provide good outcome. My cousin suggested using the heymarket real estate sms app that was absolutely perfect as per my needs. The results were also great with it.

    ReplyDelete