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

后端 未结 2 929
青春惊慌失措
青春惊慌失措 2021-01-04 09:08

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-lo

相关标签:
2条回答
  • 2021-01-04 09:24

    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.

    0 讨论(0)
  • 2021-01-04 09:40

    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

    0 讨论(0)
提交回复
热议问题