My custom font not setting up in edit text

前端 未结 2 682
误落风尘
误落风尘 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
    
    
        
    
    
    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);
    
        }
    

提交回复
热议问题