3

I have apply an style to my EditText to change bottom line when no selected, I do it like this:

<style name="JoinMeetingEditText" parent="Widget.AppCompat.EditText">
    <item name="colorControlNormal">@color/edit_text_no_selected_color</item>
    <item name="android:textCursorDrawable">@null</item>
    <item name="android:theme">@style/JoinMeetingEditText</item>
</style>

But the cursor in the EditText is displayed like this

enter image description here

If I remove <item name="android:theme">@style/JoinMeetingEditText</item> then that line is not displayed but my edit text doesn't display correct color when no selected

This is how I definde EditText in XMl

 <android.support.design.widget.TextInputLayout
        style="@style/JoinMeetingTextInputLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/email"
            android:theme="@style/JoinMeetingEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Email"
            android:inputType="number"
            android:textColor="@color/white"
            android:textSize="16sp">

            <requestFocus />
        </EditText>
aloj
  • 3,194
  • 7
  • 27
  • 38

3 Answers3

0

You can create custom drawable like this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item 
    android:state_pressed="true"
    android:color="@color/colorAccent"
    /> <!-- pressed -->    
<item 
    android:state_focused="true"
    android:color="@color/colorPrimary"
    /> <!-- focused -->    
<item 
    android:drawable="@android:drawable/edittext_normal" 
    /> <!-- default -->
</selector>

use this custom style into background of that edittext. This may help you.

Srihari
  • 2,387
  • 9
  • 51
  • 82
  • It doesn't work. Error: Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: tag requires a 'drawable' attribute or child tag defining a drawable – aloj Nov 23 '16 at 08:16
0

Change parent of your custom theme on global "AppTheme" like this: parent="AppTheme"

or common theme, for example: parent="Theme.AppCompat.Light.NoActionBar"

In your case custom theme is used as theme for all EditText child views (including cursor view). When you set AppTheme as parent, it overlap special attributes for cursor view over EditText attributes.

I hope this helps you.

U.Dima
  • 1
0

I had the same issue. Here's how I solved it: https://stackoverflow.com/a/44036429/1439957

P.S. I recommend using a TextInputEditText as the child of your TextInputLayout instead of an EditText since TextInputEditTexts were specifically designed for this.

Community
  • 1
  • 1
Ryan
  • 3,414
  • 2
  • 27
  • 34