EditText的子类的行为不像EditText [英] Subclass of EditText isn't behaving like EditText

查看:56
本文介绍了EditText的子类的行为不像EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了 EditText 的子类.这是该子类:

I've written a subclass of EditText. Here is that subclass:

package com.package.foo;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.EditText;

public class FuturaEditText extends EditText{

    public FuturaEditText(Context context) {
        this(context, null, 0);
    }

    public FuturaEditText(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public FuturaEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        if(!isInEditMode()) {
            setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/futura.ttf"));
        }
    }

}

但是,它的行为不像 EditText ,而是 TextView .特别是,软键盘并没有引起人们的关注,它没有 EditText 格式.为什么?

yet it doesn't behave like an EditText, but a TextView. In particular, the soft keyboard isn't rising on focus and it has no EditText formatting. Why?

推荐答案

出于完整性考虑-来源:

For completeness - from the source:

public EditText(Context context, AttributeSet attrs) {
       this(context, attrs, com.android.internal.R.attr.editTextStyle);
}

因此,如果调用构造函数时没有默认样式,则默认为 editTextStyle

So, if the constructor is called with no default style, it defaults to editTextStyle

这篇关于EditText的子类的行为不像EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆