Custom EditText is not showing keyboard on focus

后端 未结 6 978
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 04:21

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...

h

相关标签:
6条回答
  • 2021-02-01 04:42

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

        et.requestFocus()
    

    and try

       android:focusable="true"
    
    0 讨论(0)
  • 2021-02-01 04:44

    add this

     android:focusable="true"
    
    0 讨论(0)
  • 2021-02-01 04:47

    Make custom EditText with Kotlin to fix focus problem:

    class MyEditText @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = android.R.attr.editTextStyle) : AppCompatEditText(context, attrs, defStyleAttr) {
    
    
     init {
        doSomething(context)
     }
    
     private fun doSomething(context: Context) {
       // TODO Set your custom font or whatever you need
     }
    
    }
    
    0 讨论(0)
  • 2021-02-01 04:47
     editText.setOnTouchListener(new OnTouchListener() 
      {
        @Override
        public boolean onTouch(View v, MotionEvent event) 
         {
             editText.setFocusableInTouchMode(true);
             return false;
         }
      });
    
    0 讨论(0)
  • 2021-02-01 05:03

    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, com.android.internal.R.attr.editTextStyle);
    }
    

    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;
    }
    
    0 讨论(0)
  • 2021-02-01 05:05
    implements KeyListener on your custom EditText Class and override methods of KeyListener
    
    0 讨论(0)
提交回复
热议问题