Change font for EditText in Android?

前端 未结 8 937
梦谈多话
梦谈多话 2020-12-10 10:17

Is there any way to change the font for a EditText in Android? I want it to match the font\'s I set for all my textViews.

相关标签:
8条回答
  • 2020-12-10 11:03

    lil late but, Simple way

     mEditTextMobileNumber.setTextSize(16.0f);
    

    if you want to change font while typing :

       // Change text size when started entering number
        mEditTextMobileNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
            }
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s == null || String.valueOf(s).equalsIgnoreCase("")) {
                    mEditTextMobileNumber.setTextSize(12.0f);
                } else {
                    mEditTextMobileNumber.setTextSize(20.0f);
                }
            }
    
            @Override
            public void afterTextChanged(Editable s) {
    
            }
        });
    
    0 讨论(0)
  • 2020-12-10 11:06
     editText.setTypeface(Typeface.SERIF); 
    

    As like as for TextView.

     <TextView
      ...
         android:typeface="serif"
      ... />
    

    Edit: Above is the XML

    0 讨论(0)
提交回复
热议问题