My custom font not setting up in edit text

前端 未结 2 643
误落风尘
误落风尘 2021-01-27 08:29
mEditText = (EditText) getContentView().findViewById( R.id.custom_text );
AssetManager assests=getContext().getBaseContext().getAssets();
Typeface tf = Typeface.createFr         


        
相关标签:
2条回答
  • 2021-01-27 08:42
    // try this way,hope this will help you...
    
    1. First of all you have create "fonts" directory under "assets" directory and put you custom fonts file on "fonts" directory.
    
    2. now try to apply this code here i used my custom fonts "Helvetica LT 45 Light_0.ttf"
    
    XML
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:gravity="center">
    
        <EditText
            android:id="@+id/edtCusomFonts"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
    
    Activity
     private EditText edtCusomFonts;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            edtCusomFonts = (EditText) findViewById(R.id.edtCusomFonts);
            Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Helvetica LT 45 Light_0.ttf");
            edtCusomFonts.setTypeface(tf);
    
        }
    
    0 讨论(0)
  • 2021-01-27 08:44

    Have a try with

    mEditText.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/DroidSansFallback.ttf"));
    
    0 讨论(0)
提交回复
热议问题