Skip to content Skip to sidebar Skip to footer

How To Customize Edittext Field In Android Using Appcompat V7:21

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

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:

<stylename="AppTheme"parent="Theme.AppCompat.NoActionBar"><!-- Customize your theme here. --><itemname="colorPrimary">@color/md_red_500</item><itemname="colorPrimaryDark">@color/md_red_700</item><itemname="colorAccent">@color/md_blue_A200</item><itemname="colorControlHighlight">@color/md_black_1000_25</item><itemname="colorControlNormal">@color/md_black_1000_50</item><itemname="colorSwitchThumbNormal">@color/md_grey_200</item><itemname="android:colorForeground">@color/md_black_1000_75</item><itemname="android:windowTranslucentNavigation">@bool/translucentNavigationBar</item><itemname="android:windowTranslucentStatus">@bool/translucentStatusBar</item><!-- Navigation Drawer Arrow Style. --><itemname="drawerArrowStyle">@style/DrawerArrowStyle</item><!-- Overflow Button Style. --><itemname="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

Post a Comment for "How To Customize Edittext Field In Android Using Appcompat V7:21"