I have a custom component that extends TextView. In the constructor I set the textSize to 14.
In the layout file, I try to explicitly set the textSize to 20, but the value of the attribute has no effect.
What is the correct way to solve this?
Thanks
Code
public class MyTextView extends TextView {
public MyTextView(Context context) {
super(context);
setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
}
}
Layout
<package.MyTextView
android:text="@string/hello"
android:textSize="20sp" />
Check the attributes that you get from the XML layout in the constructor. If textSize is defined there, do not set your default textSize. see the view docs for more info.