This is a 'bug' that I discovered while working on a real app, but I created a blank project to reproduce it.
I have the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/root"
android:orientation="vertical"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.example.test.testapp.MyEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
The class MyEditText
looks like this:
public class MyEditText extends EditText {
public MyEditText(Context context){
super(context);
}
public MyEditText(Context context, AttributeSet attrs){
super(context, attrs);
}
public MyEditText(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
}
}
My styles.xml
file is empty except for the Theme
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
I would expect the MyEditText
to look like the normal EditText
and it does on Android 5.0, but not on Android 2.3.7, Android 4.1.3 or Android 4.4.4.
On those Android versions the EditText
s differ in color, the normal one has a cyan underline when focused, the custom one has a black underline:
Why is this happening and how can I prevent it?
EDIT / UPDATE:
Google seems to have adressed this in the support library by introducing, amongst others, an AppCompatEditText class.