View Extending EditText Loses Styles And Is Not Focusable
I try to subclass EditText for convenience reasons (NumberEdit) using kotlin but the rendered View loses most of the EditText properties. The look is that of a TextView and it is n
Solution 1:
I'm not a kotlin expert but if you look at the java source code for edittext you have following:
public class EditText extends TextView {
public EditText(Context context) {
this(context, null);
}
public EditText(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.editTextStyle);
}
public EditText(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public EditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
It doesn't look like you pass the right parameters to the constructor... You pass a lot of 0s and nulls...
Solution 2:
In Kotlin you can write this much more concise:
class EditNumber @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = R.attr.editTextStyle,
defStyleRes: Int = 0
) : EditText(context, attrs, defStyle, defStyleRes)
Notice the defStyle
parameter.
Post a Comment for "View Extending EditText Loses Styles And Is Not Focusable"