Change the edittext and selection color in edittext

Asked

Viewed 3,874 times

2

I am using a Autocompletetextview and an Edittext, for email and password, respectively. Is it possible to change their color? Here is an image: Change the selection color and the color on the screen:

Alterar a cor de seleção e a cor na tela

XML:`

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <AutoCompleteTextView
                android:id="@+id/email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusableInTouchMode="true"
                android:hint="@string/prompt_email"
                android:inputType="textEmailAddress"
                android:maxLines="1"
                android:singleLine="true"
                android:textColor="#D3D3D3"
                android:textSize="12dp"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:hint="@string/prompt_password"
                android:imeActionId="@+id/login"
                android:imeActionLabel="@string/action_sign_in_short"
                android:imeOptions="actionUnspecified"
                android:inputType="textPassword"
                android:maxLines="1"
                android:singleLine="true"
                android:textColor="#D3D3D3"
                android:textSize="12dp"/>

        </android.support.design.widget.TextInputLayout>

` Thank you

1 answer

4


Try this, add these styles to your style.xml:

<style name="StyledTilEditTextTheme">
    <item name="colorControlNormal">#e6ffffff</item> // Cor padrão da linha
    <item name="colorControlActivated">#faffffff</item> // Cor linha e texto quando recebe foco
</style>

<style name="StyledTilEditText">
    <item name="android:theme">@style/StyledTilEditTextTheme</item>
    <item name="android:paddingTop">4dp</item>
    <item name="android:textColorHint">#c8ffffff</item> // Cor texto(hint) sem foco
</style>

And in his TextInputLayout refer to the style you have just created:

<android.support.design.widget.TextInputLayout 
   style="@style/StyledTilEditText"
   ... Seu width e blablabla>

   ... Seu EditText

</android.support.design.widget.TextInputLayout>

Explaining (to those who do not understand):

<item name="colorControlNormal">#e6ffffff</item> // É a cor padrão da linha que fica embaixo do EditText

<item name="colorControlActivated">#faffffff</item> // Cor da linha e do texto hint(no seu caso email) quando receber foco(clique)

<item name="android:textColorHint">#c8ffffff</item> // É a cor normal do texto hint(email) 

The above example will look like this:
exemplo

  • So, I already had a custom style, it changes the color of the line, but the text "email for example", which continues in black and the selection still in "pink".

  • You tried to use the code I put in

  • These days I was also looking for how to change this and after researching many topics I managed to join this ai kk

  • In my example the colors are white because my background is black.

  • Bruno, thank you, worked yes, my brain was slow in explaining there. Thank you very much!

  • That nothing, I also took too long to get it to work kkkk

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.