Changing edittext color in android

how to change color of TextinputLayout’s label and edittext underline android

I am using android design library’s TextinputLayout . But couldn’t customize the hint color, label color and the underline color of EditText inside TextinputLayout . Please help.

13 Answers 13

Change bottom line color:

For more info check this thread.

Change hint color when it is floating

and use it like this:

Change hint color when it is not a floating label:

Based on Fedor Kazakov and others answers, I created a default config.

You can apply a custom style to change the colors.

To change the hint color you have to use these attributes:
hintTextColor and android:textColorHint .

You should use a selector for the android:textColorHint . Something like:

To change the bottom line color you have to use the attribute: boxStrokeColor .

Also in this case you should use a selector. Something like:

You can also apply these attributes in your layout:

Источник

Change color of EditText android

I have an EditText on Dark background. My EditTexts are of black color only(if not focused), so not visible properly. How can I change the color? Below is the screenshot.

6 Answers 6

Your question is about the Android theme stuff.Maybe you should set your theme’s colorControlNormal value.Just like below:

Are you using the AppCompat library? If yes you can override the style attributes colorControlNormal , colorControlActivated and colorControlHighlight .

Try this might be help you

Add this at your style.xml

Add this your drawable

If it not work then add this also

its work for me

Its might be help you.Good Luck

The easiest way to change line color in edittext is to write this in your xml file:

Not the answer you’re looking for? Browse other questions tagged android android-layout android-edittext android-styles or ask your own question.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.12.3.40888

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Change background color of edittext in android

If I change the background color of my EditText using the below code, it looks like the box is shrunken and it doesn’t maintain the ICS theme of a blue bottom border that exists for a default EditText .

Here is what it looks like:

10 Answers 10

one line of lazy code:

Here the best way

First : make new xml file in res / drawable name it rounded_edit_text then paste this:

Читайте также:  Зачем нужна калибровка батареи android

Second: in res/layout copy and past following code (code of EditText )

I create color.xml file, for naming my color name (black, white. )

And in your EditText, set color

or use style in you style.xml:

and add ctreated style to EditText:

What you should do is to create a 9 patch image for edittext and set that image as edit text background. You can create 9 patches using this website

I am attaching a sample 9 patch image for your reference.Use it as edittext background and you will get an idea.Right click the image and select «save image as». When you save the image dont forget to give its extension as «9.png»

The color you are using is white «#ffffff» is white so try a different one change in the values if you want until you get your need from this link Color Codes and it should go fine

The simplest solution I have found is to change the background color programmatically. This does not require dealing with any 9-patch images:

Источник

How to change line color in EditText

I am creating an EditText in my layout xml file

But I want to change color line in EditText from Holo to (for example) red. How that can be done?

21 Answers 21

This is the best tool that you can use for all views and its FREE many thanks to @Jérôme Van Der Linden.

The Android Holo Colors Generator allows you to easily create Android components such as EditText or spinner with your own colours for your Android application. It will generate all necessary nine patch assets plus associated XML drawable and styles which you can copy straight into your project.

UPDATE 1

This domain seems expired but the project is an open source you can find here

this image put in the background of EditText

UPDATE 2

For API 21 or higher, you can use android:backgroundTint

Update 3 Now We have with back support AppCompatEditText

Note: We need to use app:backgroundTint instead of android:backgroundTint

Update 4 AndroidX version

I don’t like previous answers. The best solution is to use:

android:backgroundTint for EditText works only on API21+ . Because of it, we have to use the support library and AppCompatEditText .

Note: we have to use app:backgroundTint instead of android:backgroundTint

AndroidX version

You can also quickly change the EditText’s underline color by tinting the background of the EditText like so:

for API below 21, you can use theme attribute in EditText put below code into style file

use this style in EditText as

Programmatically, you can try:

Its pretty simple (Required: Minimum API 21).

  1. Go to your xml and select the EditText field
  2. On the right side, you can see the ‘Attributes’ window. Select ‘View All Attributes’
  3. Just search for ‘tint’
  4. And add/change the ‘backgroundTint’ to a desired color hex (say #FF0000)

i think the best way is by theme:

You can change the color of EditText programmatically just using this line of code: edittext.setBackgroundTintList(ColorStateList.valueOf(yourcolor));

To change Edittext’s underline color:

If you want the entire app to share this style, then you can do the following way.

Читайте также:  Гарнитура блютуз jabra для андроида

(1) go to styles.xml file. Your AppTheme that inherits the parent of Theme.AppCompat.Light.DarkActionBar (in my case) will be the base parent of all they style files in your app. Change the name of it to “AppBaseTheme’. Make another style right under it that has the name of AppTheme and inherits from AppBaseTheme that you just edited. It will look like following:

Then change the “colorAccent” to whatever the color you want your EditText line color to be.

Источник

Change EditText hint color when using TextInputLayout

I am using the new TextInputLayout from the design library. I am able to get it to show and to change the color of the floating label. Unfortunately the actual EditText hint is now always white.

I have tried changing the hintColor in XML, styles, and programmatically and also tried using the android.support.v7.widget.AppCompatEditText but the EditText hint always shows white.

Here is my XML for my TextInputLayout and EditText

And here is the style I am using for the TextInputLayout (I tried making the hintTextColor attribute black but didn’t do anything for me):

28 Answers 28

Define android:textColorHint in your application theme:

Create custom style in style.xml

Then in your layout xml file, add theme attribute as below

hope this works

Add textColorHint property to your edit text

or whichever color you want

got the same problem. Resolved by putting these lines in parent theme.

If you put these

in a separate style and apply it to TextInputLayout or Edittext it won’t appear. You HAVE to place it in application’s parent theme.

I’m not sure what causes your problem put this code works perfectly for me. I think it has something to do with using the correct xml namespace ( xmlns ). I’m not sure if using android.support.design without xml namespace attribute is supported. Or it has something to do with the textColorHint attribute you are using on the EditText itself.

Refer the below code it worked for me.But it will affect all your controls color.

With the Material Components library you can customize the TextInputLayout the hint text color using:

  • app:hintTextColor attribute : the color of the label when it is collapsed and the text field is active
  • android:textColorHint attribute: the color of the label in all other text field states (such as resting and disabled)

In the TextInputLayout that holds the EditText, add:

A lot answers but need only a line for this:

android:textColorHint=»#000000″

if you are using the Material design library. Currently, I am using the version

implementation ‘com.google.android.material:material:1.3.0-alpha01’

1 — Set color when TextInputLayout is resting.

2 — Set color when TextInputLayout is floating/focused/tapped.

3 — Set color of the line under TextInputLayout.

4 — Set color of the error under TextInputLayout.

android:textColorHint=»#FFFFFF» sometime works and sometime doesnt. For me below solution works perfectly

Try The Below Code It Works In your XML file and TextLabel theme is defined in style.xml

In Styles Folder TextLabel Code

If you just want to change the color of label in false state then colorAccent , colorControlNormal and colorControlActivated are not required

You can use android:textColorHint=»@color/color_black» inside TextInputlayout It worked for me.

It works in 23.1.1

Читайте также:  Root доступа для андроида

Looks like the parent view had a style for a 3rd party library that was causing the EditText to be white.

Once I removed this everything worked fine.

try this may this help

Use textColorHint to set the color that you want as the Hint color for the EditText. The thing is that Hint in the EditText disappears not when you type something, but immediately when the EditText gets focus (with a cool animation). You will notice this clearly when you switch focus away and to the EditText.

late but it may help someone i have done like this

change your colorAccent to your desired color inside your Theme,this will change your EditText line,Cursor as well as your hint

or you can also include this style inside your style.xml

then inside your TextInputLayout you can put it like this

From the documentation:

The hint should be set on the TextInputLayout, rather than the EditText. If a hint is specified on the child EditText in XML, the TextInputLayout might still work correctly; TextInputLayout will use the EditText’s hint as its floating label. However, future calls to modify the hint will not update TextInputLayout’s hint. To avoid unintended behavior, call setHint(CharSequence) and getHint() on TextInputLayout, instead of on EditText.

Try setting android:hint and app:hintTextColor on TextInputLayout instead of on TextInputEditText .

If you are using new androidx Material design library com.google.android.material then you can use colorstatelist to control hint text color in focused, hovered and default state as follows. (inspired by this)

In res/color/text_input_box_stroke.xml put something like the following:

Then in your styles.xml you would put:

Finally indicate your style in the actual TextInputLayout For some reason you also need to set android:textColorHint for default text color of hint:

You must set hint color on TextInputLayout.

When I tried to set theme attribute to TextInputLayout, the theme was also getting applied to its child view edittext, which I didn’t wanted.

So the solution which worked for me was to add a custom style to the «app:hintTextAppearance» property of the TextInputLayout.

In styles.xml add the following style:

And apply this style to the «app:hintTextAppearance» property of the TextInputLayout as below:

Here is the complete customization of the google material text input layout. This maybe helpful for you

The high light color is White:

Here is my experience with this similar issue & the required solution.

Requirement:

  • Need to create customize TextInputEditText (can say some should be transparent and some should be not but use custom colors for various events)

Problem faced:

  • android:textColorHint is not working as required.

Solutions tried, which failed:

  • Used android:textColorHint in style and applied to TextInputEditText . No results or difference.
  • Set android:textColorHint in application’s theme applied. It do helped but it was now set for entire application. (Not up-to mark to requirement)

After a lot of RnD, the best SOLUTION found was in an article which described that we need to apply theme to TextInputLayout or to it’s parent view rather then only applying style to TextInputEditText or to it’s parent view.

Please check TextInputLayout proper Theming which told that how we are at wrong track.

Источник

Оцените статью