I started using AppCompat-v7 for use the concept of Material Design in my project . But now I realized that my custom components even inheriting from native components are not applying themes like native components, for example:
I have the following custom component inheriting from android.widget.EditText
:
public class EditTextPro extends android.widget.EditText {
public EditTextPro(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
And in my layout I use the EditTextPro
component like this:
<com.app.materialtest.EditTextPro
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/view"
android:layout_below="@+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
And another with a native component android.widget.EditText
like this:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText3"
android:layout_below="@+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
I'm using the following theme:
<style name="AppTheme" parent="Theme.AppCompat">
<!-- customize the color palette -->
<item name="colorPrimary">@color/palette_primary</item> <!-- #3F51B5 = Azul -->
<item name="colorPrimaryDark">@color/palette_primary_dark</item> <!-- #303F9F = Azul Forte -->
<item name="colorAccent">@color/palette_accent</item> <!-- #FF4081 = Rosa -->
</style>
And the result of the 2 EditText is as follows (the first is the android.widget.EditText
and the second the com.app.materialtest.EditTextPro
):
Focusing on android.widget.EditText
colorAccent
is displayed on the EditText
line:
Alreadyfocusingoncom.app.materialtest.EditTextPro
colorAccent
isnotdisplayedontheEditText
line:
And even without focus, the colors shown are different, with a shade of gray for android.widget.EditText
and Black for com.app.materialtest.EditTextPro
Questions:
- Why does this occur? Since I do not make any changes in the styles of
com.app.materialtest.EditTextPro
in relation toandroid.widget.EditText
, being that for logic (my logic = D) it was forcom.app.materialtest.EditTextPro
to inherit all styles ofandroid.widget.EditText
. Right? - Is there any way to resolve this? Make
com.app.materialtest.EditTextPro
have the same styles asandroid.widget.EditText
. - Should I inherit instead of
android.widget.EditText
of someEditText
of the support API? (Note: I looked in the support API and found noEditText
).
Note: I'm running on Android 4.4.4.