0

I have this layout:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:textColorHint="@android:color/white">
        <EditText android:id="@+id/input_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textCapWords"
            android:hint="Name" />
    </android.support.design.widget.TextInputLayout>

And I want to change the Hint Text form Java when a switch button is touched, but this is what happens using this code:

 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
        {
            if (isTouched) {
                isTouched = false;
                if (isChecked) {
                    _nameText.setHint("Shop Name");
                    _inputPiva.setHint("ho la cacca");
                }
                else {
                    _nameText.setHint("Name");
                }
            }
        }

enter image description here

enter image description here

How can I set the hint like the light-blue one?

Surya Prakash Kushawah
  • 3,185
  • 1
  • 22
  • 42
Johnson
  • 297
  • 2
  • 5
  • 18

1 Answers1

1

Step1: "Programatic":editText.setHintTextColor(getResources().getColor(R.color.white));

Step2: "Xml":android:textColorHint="#FFFFFF"

You can get the hint of edittext like this

    editText.setHint("My conditional hint");
    final String str = hi.getHint().toString();

Then after toggle Onclick listener place the code

editText.setText(str); //It will replace the text 
Rajakumar
  • 907
  • 1
  • 7
  • 17