Android - AppCompatEditText theme not being applied inside fragment
I added a new library app-compat 'com.android.support:appcompat-v7:22.1.0' to my project, but it seems the problem is applying the theme to AppCompatEditText when it's inside a fragment.
This is my EditText:
<android.support.v7.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@color/teal_300"
android:textCursorDrawable="@null"
android:textColorHint="@color/text_hint"
style="@style/TextAppearance.AppCompat.Display1"
android:theme="@style/Theme.MyTheme.EditText"/>
This is the topic:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/teal_500</item>
<item name="colorPrimaryDark">@color/teal_700</item>
<item name="colorAccent">@color/orange_500</item>
<item name="colorControlNormal">@color/grey</item>
<item name="colorControlActivated">@color/teal_300</item>
<item name="colorControlHighlight">@color/teal_300</item>
<item name="colorSwitchThumbNormal">@color/teal_300</item>
</style>
<style name="Theme.MyTheme.EditText" parent="Theme.MyTheme">
<item name="colorControlNormal">@color/orange_500</item>
<item name="colorControlActivated">@color/orange_500</item>
</style>
So basically I just want to change the EditText's underline color to orange and not gray / teal.
When I put this code directly into the activity layout, it works great, so the underline is orange. But if I put the same code inside the fragment layout, the underline is greyed out / blank. So the theme doesn't apply.
thank
+3
source to share
2 answers
You should use style instead of theme for the EditText, for example:
<style name="EditText" parent="Widget.AppCompat.EditText">
<item name="colorControlNormal">@color/orange_500</item>
<item name="colorControlActivated">@color/orange_500</item>
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Display1</item>
</style>
Than only the style and theme are applicable.
0
source to share