我自己制作了 DroidParts ClearableEditText
的修改版本,Android Studio 给了我以下错误:
This custom view should extend
android.support.v7.widget.AppCompatEditText
instead.In order to support features such as tinting, the appcompat library will automatically load special appcompat replacements for the builtin widgets. However, this does not work for your own custom views.
Instead of extending the android.widget classes directly, you should instead extend one of the delegate classes in
android.support.v7.widget.AppCompat
.
但是,当我更改我的 ClearableEditText
类以扩展该类时,当我聚焦文本字段时键盘永远不会出现。
我知道我可以返回直接扩展 EditText
,但我想按照推荐的方式进行。我怎样才能做到这一点并让键盘显示出来?
最佳答案
确保每个构造函数都使用 super 而不是 this() 。我在扩展 AppCompatEditText 时面临同样的问题
工作代码:
public RichEditText(Context context) {
super(context);
}
public RichEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RichEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
关于android - 扩展 AppCompatEditText 时无法显示键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46896630/