Custom EditText is not showing keyboard on focus

I am creating a custom EditText class because i need to set some custom fonts; However now when i click on the editText the android keyboard does not pop up anymore…

here is my class:

  • Eclipse / Android : “Errors running builder 'Android Pre Compiler' on project…”
  • Remove space between buttons in LinearLayout (Android)
  • How to test custom URL scheme in android
  • Check for file existence in androids assets folder?
  • Call Activity method from adapter
  • How do I properly import HttpClient from org.apache on Android using gradle build file?
  •     package ro.gebs.captoom.utils.fonts;
    import android.content.Context;
    import android.content.res.TypedArray;
    import android.util.AttributeSet;
    import android.view.inputmethod.InputMethodManager;
    import android.widget.EditText;
    import ro.gebs.captoom.R;
    public class CustomFontEditText extends EditText {
        private Context context;
        public CustomFontEditText(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            if (!isInEditMode()) {
                TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomFontEditText,
                        defStyle, 0);
                assert a != null;
                int fontId = a.getInteger(R.styleable.CustomFontEditText_fontNameEdit, -1);
                if (fontId == -1) {
                    throw new IllegalArgumentException("The font_name attribute is required and must refer "
                            + "to a valid child.");
            this.context = context;
        public CustomFontEditText(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
            this.context = context;
        public CustomFontEditText(Context context) {
            this.context = context;
        public void initialize(int fontId) {
            Typeface tf = null;
            switch (fontId) {
                case 0:
                    tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Regular.ttf");
                case 1:
                    tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Bold.ttf");
                case 2:
                    tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-Semibold.ttf");
                case 3:
                    tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/OpenSans-ExtraBold.ttf");

    and how i use it in XML:

                            custom:fontNameEdit="Regular" />

    I thought the focusing events were handled by the fact that i extend the EditText class…

    Any hints?

  • Android: What does this warning message refer to? - (WebCore)
  • Error using Android Design Support Library: attr backgroundTint not found
  • Embedding ads within Recyclerview
  • findViewById retrurns wrong element?
  • Intent.ACTION_PICK returns empty cursor for some contacts
  • Reset Android textview maxlines
  • 5 Solutions collect form web for “Custom EditText is not showing keyboard on focus”

     editText.setOnTouchListener(new OnTouchListener() 
        public boolean onTouch(View v, MotionEvent event) 
             return false;

    It’s an old question but if someone cares, the problem is on the implementation of the constructor:

    public CustomFontEditText(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        this.context = context;

    The last argument (“defStyle”) which you set as 0, should be the default style for an EditText. If you take a look at the same constructor on the EditText class:

    public EditText(Context context, AttributeSet attrs) {
        this(context, attrs,;

    As you can see, the default style for an EditText should be used, so your constructor should look like this:

    public CustomFontEditText(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.editTextStyle);
        this.context = context;

    add this

    implements KeyListener on your custom EditText Class and override methods of KeyListener

    try to make reference for edit text at runtime and call request focus()


    and try

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.