Skip to main content

Android-How to change your Text to different Styles.


       Everyone wanna present their apps stylish .Font Styles have one of the great part while presenting your app.


       All you need is True Type Font(ttf) file of your desired styles(Ex:Amalgam.ttf ).you can download them from here or you can get all ttf files by searching over the Internet.

 
       paste it (or them ) in your assets folder  like below,


















     
In your xml file create the Textviews like below,



<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" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="amelia"
        tools:context=".MainActivity" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="28dp"
      android:text="Airacobralight"/>

    <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="32dp"
         android:text="Amalgam"/>

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

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView3"
        android:layout_below="@+id/textView3"
        android:layout_marginTop="30dp"
         android:text="DroidSans"/>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView4"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="36dp"
       android:text="DroidSerifBoldItalic" />

</RelativeLayout>


Call all textviews in your Java File and set typefaces,



package com.example.accessfromassets;

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

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
       

      //findId from xml file 
       
  TextView tv=(TextView)findViewById(R.id.textView1);
  TextView tv1=(TextView)findViewById(R.id.textView2);
  TextView tv2=(TextView)findViewById(R.id.textView3);
  TextView tv3=(TextView)findViewById(R.id.textView4);
  TextView tv4=(TextView)findViewById(R.id.textView5);
  TextView tv5=(TextView)findViewById(R.id.tv);

  //getting .ttf files from assets
 
 Typeface amelia = Typeface.createFromAsset(getAssets(), "Amelia.ttf"); 
 Typeface Airacobralight = Typeface.createFromAsset(getAssets(), "Airacobra Light.ttf");
 Typeface Amalgam = Typeface.createFromAsset(getAssets(), "Amalgam.ttf"); 
 Typeface AiracobraAlt = Typeface.createFromAsset(getAssets(), "Airacobra Alt.ttf");
 Typeface DroidSans = Typeface.createFromAsset(getAssets(), "DroidSans.ttf");
 Typeface DroidSerifBoldItalic = Typeface.createFromAsset(getAssets(), "DroidSerif-BoldItalic.ttf");



 //set typefaces to the textviews

 tv.setTypeface(amelia);
 tv1.setTypeface(Airacobralight);
 tv2.setTypeface(Amalgam);
 tv3.setTypeface(AiracobraAlt);
 tv4.setTypeface(DroidSans);
 tv5.setTypeface(DroidSerifBoldItalic);
    }

}
 


The Result will be like below,


    

Comments

Post a Comment

Popular posts from this blog

Circular Seek Bar - Example

MyView.java package com.rakesh.androidcircularseekbar; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; public class MyView extends View {     /** The context */     private Context mContext;     /** The listener to listen for changes */     private OnSeekChangeListener mListener;     /** The color of the progress ring */     private Paint circleColor;     /** the color of the inside circle. Acts as background color */     private Paint innerColor;     /** The progress circle ring background */     private Paint circleRing;   ...

SSL pinning in Android - A brief discussion

HTTP protocol Communication between the client and a server typically non-encrypted or plain text while we use HTTP protocol.  Pitfall Any middle hacker can interrupt the connection between the client and server and manipulate the data as it involves no encryption. How to overcome this ? As the domain owner one can purchase a digital certificate from CA(Certificate Authority) who are considered as trusted.  A certificate will contain the Owner's name, public key , Issuer's(CA's) name,Issuer's(CA's) signature, domain details, expiry date etc . After the SSL/Leaf certificate is associated with a domain,the communication between client and server will be encrypted. Now the HTTP will become HTTPs. Note : Associating the SSL certificate means it enable the encryption between client and server but does not mean ,the domain owner will never misuse your personal information. How does SSL work ? Pitfall There is a problem here. Let's assume that there is a hacker comes i...

Android-PageViewer

source code   here I've searched for a page Viewer to swipe the pages for the better view .. I found some of the snippets while searching for that ... I used  the dotted Indication using  CirclePageIndicator in my package "com.rakesh.view" The Java files in this package are CirclePageIndicator.java public class CirclePageIndicator extends View implements PageIndicator {     private static final int INVALID_POINTER = -1;     private float mRadius;     private final Paint mPaintPageFill = new Paint(ANTI_ALIAS_FLAG);     private final Paint mPaintStroke = new Paint(ANTI_ALIAS_FLAG);     private final Paint mPaintFill = new Paint(ANTI_ALIAS_FLAG);     private ViewPager mViewPager;     private ViewPager.OnPageChangeListener mListener;     private int mCurrentPage;     private int mSnapPage;    ...