1

I am trying to create editText having floating hint using Android TextInputLayout. I want to reuse the same TextInputLayout in two layouts.But in both the layout hint color is different. I searched through several links and found that we can set hint color in edittext(not the floating hint color) by adding

android:textColorHint="@color/white" in TextInputLayout.

But how to do it programatically as in other layout color needs to be different

PS: setTextAppearanceHint() is not working.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
stack Learner
  • 1,318
  • 3
  • 18
  • 35
  • you are using edittext inside TextInputLayout. right? – Shweta Chauhan Nov 02 '17 at 08:54
  • 2
    Possible duplicate of [How to change the floating hint color of TextInputLayout if EditText inside is disabled](https://stackoverflow.com/questions/35738544/how-to-change-the-floating-hint-color-of-textinputlayout-if-edittext-inside-is-d) – AskNilesh Nov 02 '17 at 09:06
  • Try this: [kotlin version](https://stackoverflow.com/a/57184478/10997485) Hope this helps you. – Sergey Rusak Jul 25 '19 at 05:43

2 Answers2

0

Try with setHintTextAppearance

setHintTextAppearance(R.style.my_style);

Then

<style name="my_style" parent="TextAppearance.AppCompat">
<item name="android:textColor">#54D66A</item>

For more details you can check TextInputLayout accent color programmatically.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

You can give this a try. The TextView in TextInputLayout has an id R.id.textinput_error

So,

tv = (TextView) textInputLayout.findViewById(R.id.textinput_error);
tv.setTextColor(int resId);
Geet Choubey
  • 1,069
  • 7
  • 23