我的CustomTextView有问题.我正在尝试从我的layout-xml文件中获取自定义值并在我的setText()方法中使用它.不幸的是,在构造函数之前调用了setText()方法,因此我无法在此方法中使用自定义值.
这是我的代码(细分到相关部分):
public class CustomTextView extends TextView {
private float mHeight;
private final String TAG = "CustomTextView";
private static final Spannable.Factory spannableFactory = Spannable.Factory.getInstance();
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
Log.d(TAG, "in CustomTextView constructor");
TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.CustomTextView);
this.mHeight = values.getDimension(R.styleable.CustomTextView_cHeight, 20);
}
@Override
public void setText(CharSequence text, BufferType type) {
Log.d(TAG, "in setText function");
Spannable s = getCustomSpannableString(getContext(), text);
super.setText(s, BufferType.SPANNABLE);
}
private static …Run Code Online (Sandbox Code Playgroud)