-5

I have two edit text.First one is email and the second one is a password field.
When I click login button without filling the both fields, the hint color and underline changes to red color in both fields are an unfocused state.
unfocused state at the landing page, the color should be in blue colorenter image description here while clicking login without filling fields in the unfocused stateenter image description here.

This is my requirement.
I have tried all possible ways to achieve this scenario.
But I cant control focused and unfocused state.
Please guide me to solve this issues.

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="colorControlActivated">@color/primary</item> <item name="colorControlHighlight">@color/colorPrimary</item> </style>

i want to change the hint color,underline color in unfocused state programmatically.

colors.xml

<resources> <color name="primary">#1976d2</color> <color name="primary_dark">#E12929</color> <color name="primary_darker">#CC1D1D</color> <color name="accent">#000000</color> <color name="blue">#1976d2</color> <color name="black">#000000</color> <color name="lightblue">#1976d2</color> <color name="lightgray">#666666</color> </resources>
user8367573
  • 111
  • 1
  • 7
  • Use TextInputLayout – MinnuKaAnae Jul 26 '17 at 05:27
  • That blue when landing means it is your colorprimary that you mentioned in colors.xml. post your styles.xml and colors.xml – MinnuKaAnae Jul 26 '17 at 06:08
  • – user8367573 Jul 26 '17 at 06:17
  • 1
    Pls edit your question by posting with styles.xml and colors.xml – MinnuKaAnae Jul 26 '17 at 06:25
  • i want to change the hint color,underline color in unfocused state programmatically.colors.xml #1976d2 #E12929 #CC1D1D #000000 #1976d2 #000000 #1976d2 #666666 – user8367573 Jul 26 '17 at 06:51
  • Don't post code in comments, please. – Phantômaxx Jul 26 '17 at 07:00

4 Answers4

0

Something like you should try

<android.support.design.widget.TextInputLayout
android:id="@+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
    android:id="@+id/username"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:hint="Username"/>

</android.support.design.widget.TextInputLayout>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
MinnuKaAnae
  • 1,646
  • 3
  • 23
  • 35
0

try this

TextInputLayout emailInput, passInput;
EditText edtEmail, edtPass;
Button btnLogin;
String hintEmail = "",hintPass="";


emailInput = (TextInputLayout) findViewById(R.id.emailInput);
passInput = (TextInputLayout) findViewById(R.id.passInput);

edtEmail = (EditText) findViewById(R.id.edtEmail);
edtPass = (EditText) findViewById(R.id.edtPass);

btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(this);


    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (edtEmail.getText().toString().trim().isEmpty()) {
                edtEmail.setHint("please enter Email Address ");
                hintEmail = "please enter Email Address ";
                edtEmail.setHintTextColor(ContextCompat.getColor(this,R.color.colorRed));
                emailInput.setHint("");

            }

            if (edtPass.getText().toString().trim().isEmpty()) {
                edtPass.setHint("please enter Password ");
                hintPass = "please enter Password  ";
                edtPass.setHintTextColor(getResources().getColor(R.color.colorRed));
                passInput.setHint("");

            }

        }
    });
    edtEmail.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            emailInput.setHint(hintEmail);
            edtEmail.setHint("");
            return false;
        }
    });
    edtPass.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            passInput.setHint(hintPass);
            edtPass.setHint("");
            return false;
        }
    });
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

Try something below like this,For make error to edittext useinputLayout.setError("Enther somehting");after validate your condition you have to remove using setErrorEnabled(false)

  inputLayout_et = (TextInputLayout) findViewById(R.id.input_layout_newpassword);

  inputLayout_et.setErrorEnabled(false);
piet.t
  • 11,718
  • 21
  • 43
  • 52
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
0

hint color

android:textColorHint="@color/red"
Uma Achanta
  • 3,669
  • 4
  • 22
  • 49