12

I'm using the Appcompatv7 21 and trying to customize the editText field.

Weird thing is that it's working fine on lollipop but doesn't work on kitkat or any pre-lollipop devices. I thought support libraries worked on all platforms.

<style name="mAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="colorControlNormal">@color/veryLightGrey</item>
    <item name="colorControlActivated">@color/colorAccent</item>
    <item name="colorControlHighlight">@color/colorAccent</item>
</style>


compile 'com.android.support:appcompat-v7:21.0.3'

enter image description here

Screenshot from the physical device. Screenshot

Community
  • 1
  • 1
iitum studant
  • 856
  • 2
  • 8
  • 24
  • I think it's a bug of the Android Studio, cause on the real devices it looks as expected for me. – romtsn Jan 22 '15 at 05:52
  • @rom4ek Nope, I tried it on my device running kitkat. The underline comes black. I have no idea why.... – iitum studant Jan 22 '15 at 05:54
  • As for me I just using this two tags: `@color/main_color @color/main_color` to customize EditText's so it's working for me. – romtsn Jan 22 '15 at 06:31
  • I have the same problem, according with android developer blogspot, FAQ section describes possible causes for tint not work: "You have your own custom version of the widget (i.e. you’ve extended EditText)" or "You are creating the EditText without a LayoutInflater (i.e., calling new EditText()).". After change from my custom EditText to default EditText, this work fine! – Taynã Bonaldo Mar 03 '15 at 15:39
  • Had the same problem: I forgotten to extend ActionBarActivity – Korniltsev Anatoly May 19 '15 at 21:25

2 Answers2

10

Try to add the next code inside your EditText

style="@style/Widget.AppCompat.EditText"

Check in real device.

In my EditText works, this is my EditText:

<EditText
    android:id="@+id/editTextFacebookID"
    style="@style/Widget.AppCompat.EditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_marginLeft="64dp"
    android:layout_marginRight="8dp"
    android:gravity="center_vertical"
    android:hint="Facebook ID"
    android:textColor="@color/md_text"                
    android:textColorHint="@color/md_disabled_hint_text" />

You can check md_text and md_disabled_hint_text colors here: Google Colors

And this is a v19 style of my app:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/md_red_500</item>
    <item name="colorPrimaryDark">@color/md_red_700</item>
    <item name="colorAccent">@color/md_blue_A200</item>
    <item name="colorControlHighlight">@color/md_black_1000_25</item>
    <item name="colorControlNormal">@color/md_black_1000_50</item>
    <item name="colorSwitchThumbNormal">@color/md_grey_200</item>
    <item name="android:colorForeground">@color/md_black_1000_75</item>
    <item name="android:windowTranslucentNavigation">@bool/translucentNavigationBar</item>
    <item name="android:windowTranslucentStatus">@bool/translucentStatusBar</item>

    <!-- Navigation Drawer Arrow Style. -->
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

    <!-- Overflow Button Style. -->
    <item name="actionOverflowButtonStyle">@style/OverflowStyle</item>
</style>

My EditText is gray when is unfocused, and blue focused, it takes the color from colorAccent.

It changes color when I change the AppTheme.

Ali Turki
  • 1,265
  • 2
  • 16
  • 21
JavierSegoviaCordoba
  • 6,531
  • 9
  • 37
  • 51
2

Even better, just change it from EditText to AppCompatEditText and you're good. Benefit from the AppCompat you're already using.

src: http://android-developers.blogspot.ae/2014/10/appcompat-v21-material-design-for-pre.html

Samer
  • 536
  • 3
  • 5