Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to create Custom font function in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 266
    Comment on it

    If you are looking to make Custom Font in android check the below code example. For this first download the required fonts on your system and then place it in fonts folder. After putting fonts in the assets/fonts folder then I have used java code through Typeface class. See Below code example it will clearly described you how to create Custom font function.

    Step(1)-styles.xml

    <style name="TextStyle">
     <item name="android:layout_width">match_parent</item>
     <item name="android:layout_height">wrap_content</item>
     <item name="android:textSize">@dimen/text_size</item>
     <item name="android:layout_marginTop">@dimen/text_margin_top</item>
    </style>
    

    Step(2)-dimens.xml

    <resources>
        <dimen name="activity_padding">10dp</dimen>
        <dimen name="text_size">40sp</dimen>
        <dimen name="text_margin_top">25dp</dimen>
    </resources>
    

    Step(3)-activity_main.xml

    <LinearLayout
        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"
        android:orientation="vertical"
        android:padding="@dimen/activity_padding"
        tools:context=".MainActivity">
    
    
        <TextView
            android:id="@+id/Evon"
            style="@style/TextStyle"
            android:text="Evon" />
    
    
        <TextView
            android:id="@+id/Apple"
            style="@style/TextStyle"
            android:text="Apple" />
    
    
        <TextView
            android:id="@+id/Microsoft"
            style="@style/TextStyle"
            android:text="Microsoft" />
    
    </LinearLayout>
    

    Step(4)MainActivity-

    public class MainActivity extends AppCompatActivity {
    
        private TextView mEvon = null;
        private TextView mApple = null;
        private TextView mMicrosoft = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            initViews();
    
    
            Typeface face_01 = Typeface.createFromAsset(getAssets(), "customfont/libertylegion.ttf");
    
             mEvon.setTypeface(face_01);
    
    
    
    
    Typeface face_02 = Typeface.createFromAsset(getAssets(),"customfont/ChronicDelivery.ttf");
    
            mApple.setTypeface(face_02);
    
    
    
    
    Typeface face_03 = Typeface.createFromAsset(getAssets(),"customfont/MilasianMediumPERSONAL.ttf");
    
            mMicrosoft.setTypeface(face_03);
    
    
        }
    
        private void initViews() {
            mEvon = (TextView) findViewById(R.id.evon);
            mApple = (TextView) findViewById(R.id.apple);
            mMicrosoft = (TextView) findViewById(R.id.microsoft);
        }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: