How to customize EditText field in android using AppCompat v7:21

38,263

Solution 1

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.

Solution 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

Share:
38,263
iitum studant
Author by

iitum studant

Updated on August 14, 2020

Comments

  • iitum studant
    iitum studant over 3 years

    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