2
I started using the Appcompat-v7, for use the concept of Material Design in my project. Only now I realized that my custom components even inherited from native components, are not applying the themes as the native components, for example:
I have the following custom component inherited 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 component EditTextPro
thus:
<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
thus:
<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 2 Edittext is the following (the first is the android.widget.EditText
and the second the com.app.materialtest.EditTextPro
):
With the focus on android.widget.EditText
the colorAccent
is displayed in the EditText
:
Already focusing on the com.app.materialtest.EditTextPro
the colorAccent
is not displayed in the EditText
:
And even without the focus the colors presented are different, being a shade of gray to the android.widget.EditText
and Black to the com.app.materialtest.EditTextPro
Questions:
- Why does this happen? Since I do not make any changes in the styles of
com.app.materialtest.EditTextPro
in relation to theandroid.widget.EditText
, and by logic (my logic =D) was for thecom.app.materialtest.EditTextPro
inherit all styles ofandroid.widget.EditText
. Right? - Is there any way to resolve this? Make the
com.app.materialtest.EditTextPro
have the same styles as theandroid.widget.EditText
. - I must inherit instead of
android.widget.EditText
of someEditText
support API? (NOTE: I searched the support API and found noneEditText
).
Note: I am running on Android 4.4.4.
Amazing that was it! Thank you very much. Our had already tried so many things that we no longer had options of "gambiarras" to try. Perfect. (Much better than these gringos, who only give options of gambiarras. here, recommend translate and post your reply there)
– Fernando Leal
@You’re welcome, I’m happy to help. I’ll translate my answer and put in the link you sent me. Thanks.
– Lucas Santos
I’m already following this line of thinking of always using the options from within
android.support.v7.app
, instead of the nativeandroid.app
(learned this after spending some time trying to understand why myActionBar
did not function as expected, and it was because it was using theandroid.app.ActionBar
), but in the case ofEditText
, They screwed up by changing the nameTintEditText
, I had already looked for someEditText
in the API of support and had not found, hehe.– Fernando Leal
Actually looking for a class that added a name on the front makes things a little more difficult. If the name were the same, I believe the IDE would warn you by telling you that there is more than one place to matter and giving you the option to choose. I already translated my answer and put in the American Stack.
– Lucas Santos
Already received my +1, there too, after all this option besides being simpler, it works, unlike the other answers there, which work in part. =)
– Fernando Leal