Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.example.tutorial;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Typeface;
  5. import android.view.LayoutInflater;
  6. import android.widget.RelativeLayout;
  7. import android.widget.TextView;
  8.  
  9.  
  10. /**
  11.  * Created by Shiburagi on 26-Jan-15.
  12.  */
  13. public class MainLayout extends RelativeLayout {
  14.  
  15.     /**
  16.      * Constructor
  17.      *
  18.      * @param context
  19.      */
  20.     public MainLayout(Context context) {
  21.         super(context);
  22.  
  23.         // call init function
  24.         init(context, null);
  25.     }
  26.  
  27.     public MainLayout(Context context, LayoutInflater inflater) {
  28.         super(context);
  29.  
  30.         // call third-party font from assets/fonts folder
  31.         Typeface typeface = Typeface.createFromAsset(context.getAssets(),
  32.                 "fonts/Square Unique Thin.ttf");
  33.        
  34.         // call init function
  35.         init(context, typeface);
  36.  
  37.  
  38.         // call and receive view from the activity_main.xml
  39.         // View view = inflater.inflate(R.layout.activity_main, null);
  40.  
  41.         // add the view into layout
  42.         // addView(view);
  43.     }
  44.  
  45.     /**
  46.      * to initialize component been used in the application
  47.      *
  48.      * @param context
  49.      * @param typeface
  50.      */
  51.     private void init(Context context, Typeface typeface) {
  52.  
  53.         // declare textview component
  54.         TextView textView = new TextView(context);
  55.  
  56.         // set value of the textview.
  57.         textView.setText("Hello World!");
  58.  
  59.         // set custom font for a view
  60.         textView.setTypeface(typeface);
  61.  
  62.         // add textview into this layout
  63.         addView(textView);
  64.  
  65.     }
  66. }